Socket
Socket
Sign inDemoInstall

@cosmjs/launchpad

Package Overview
Dependencies
Maintainers
2
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cosmjs/launchpad - npm Package Compare versions

Comparing version 0.25.2 to 0.25.3

8

build/cosmosclient.searchtx.spec.js

@@ -24,3 +24,3 @@ "use strict";

const recipient = testutils_spec_1.makeRandomAddress();
const transferAmount = amino_1.coins(123456700000000, "ucosm");
const amount = amino_1.coins(123456700000000, "ucosm");
const sendMsg = {

@@ -31,3 +31,3 @@ type: "cosmos-sdk/MsgSend",

to_address: recipient,
amount: transferAmount,
amount: amount,
},

@@ -61,4 +61,4 @@ };

const recipient = testutils_spec_1.makeRandomAddress();
const transferAmount = amino_1.coins(1234567, "ucosm");
const result = await client.sendTokens(recipient, transferAmount);
const amount = amino_1.coins(1234567, "ucosm");
const result = await client.sendTokens(recipient, amount);
await utils_1.sleep(75); // wait until tx is indexed

@@ -65,0 +65,0 @@ const txDetails = await new lcdapi_1.LcdClient(testutils_spec_1.launchpad.endpoint).txById(result.transactionHash);

import { StdFee } from "@cosmjs/amino";
import { Decimal } from "@cosmjs/math";
export declare type FeeTable = Record<string, StdFee>;
/**
* A gas price, i.e. the price of a single unit of gas. This is typically a fraction of
* the smallest fee token unit, such as 0.012utoken.
*/
export declare class GasPrice {

@@ -8,2 +12,8 @@ readonly amount: Decimal;

constructor(amount: Decimal, denom: string);
/**
* Parses a gas price formatted as `<amount><denom>`, e.g. `GasPrice.fromString("0.012utoken")`.
*
* The denom must match the Cosmos SDK 0.39 pattern (https://github.com/cosmos/cosmos-sdk/blob/v0.39.3/types/coin.go#L597-L598).
* See `GasPrice` in @cosmjs/stargate for a more generic matcher.
*/
static fromString(gasPrice: string): GasPrice;

@@ -10,0 +20,0 @@ }

@@ -6,2 +6,20 @@ "use strict";

const math_1 = require("@cosmjs/math");
/**
* Denom checker for the Cosmos SDK 0.39 denom pattern
* (https://github.com/cosmos/cosmos-sdk/blob/v0.39.3/types/coin.go#L597-L598).
*
* This is like a regexp but with helpful error messages.
*/
function checkDenom(denom) {
if (denom.length < 3 || denom.length > 16) {
throw new Error("Denom must be between 3 and 16 characters");
}
if (denom.match(/[^a-z0-9]/)) {
throw new Error("Denom must only contain lower case letters a-z and digits 0-9");
}
}
/**
* A gas price, i.e. the price of a single unit of gas. This is typically a fraction of
* the smallest fee token unit, such as 0.012utoken.
*/
class GasPrice {

@@ -12,11 +30,16 @@ constructor(amount, denom) {

}
/**
* Parses a gas price formatted as `<amount><denom>`, e.g. `GasPrice.fromString("0.012utoken")`.
*
* The denom must match the Cosmos SDK 0.39 pattern (https://github.com/cosmos/cosmos-sdk/blob/v0.39.3/types/coin.go#L597-L598).
* See `GasPrice` in @cosmjs/stargate for a more generic matcher.
*/
static fromString(gasPrice) {
const matchResult = gasPrice.match(/^(?<amount>.+?)(?<denom>[a-z]+)$/);
// Use Decimal.fromUserInput and checkDenom for detailed checks and helpful error messages
const matchResult = gasPrice.match(/^([0-9.]+)([a-z][a-z0-9]*)$/i);
if (!matchResult) {
throw new Error("Invalid gas price string");
}
const { amount, denom } = matchResult.groups;
if (denom.length < 3 || denom.length > 127) {
throw new Error("Gas price denomination must be between 3 and 127 characters");
}
const [_, amount, denom] = matchResult;
checkDenom(denom);
const fractionalDigits = 18;

@@ -23,0 +46,0 @@ const decimalAmount = math_1.Decimal.fromUserInput(amount, fractionalDigits);

@@ -14,11 +14,38 @@ "use strict";

});
it("can be constructed from a config string", () => {
const inputs = ["3.14", "3", "0.14"];
inputs.forEach((input) => {
const gasPrice = fee_1.GasPrice.fromString(`${input}utest`);
expect(gasPrice.amount.toString()).toEqual(input);
expect(gasPrice.denom).toEqual("utest");
describe("fromString", () => {
it("works", () => {
const inputs = {
// Test amounts
"3.14utest": { amount: "3.14", denom: "utest" },
"3utest": { amount: "3", denom: "utest" },
"0.14utest": { amount: "0.14", denom: "utest" },
// Test denoms
"0.14sht": { amount: "0.14", denom: "sht" },
"0.14testtesttesttest": { amount: "0.14", denom: "testtesttesttest" },
"0.14ucoin2": { amount: "0.14", denom: "ucoin2" },
};
for (const [input, expected] of Object.entries(inputs)) {
const gasPrice = fee_1.GasPrice.fromString(input);
expect(gasPrice.amount.toString()).withContext(`Input: ${input}`).toEqual(expected.amount);
expect(gasPrice.denom).withContext(`Input: ${input}`).toEqual(expected.denom);
}
});
it("errors for invalid gas price", () => {
// Checks basic format <amount><denom>
expect(() => fee_1.GasPrice.fromString("")).toThrowError(/Invalid gas price string/i);
expect(() => fee_1.GasPrice.fromString("utkn")).toThrowError(/Invalid gas price string/i);
expect(() => fee_1.GasPrice.fromString("@utkn")).toThrowError(/Invalid gas price string/i);
expect(() => fee_1.GasPrice.fromString("234")).toThrowError(/Invalid gas price string/i);
expect(() => fee_1.GasPrice.fromString("-234tkn")).toThrowError(/Invalid gas price string/i);
// Checks details of <denom>
expect(() => fee_1.GasPrice.fromString("234t")).toThrowError(/denom must be between 3 and 16 characters/i);
expect(() => fee_1.GasPrice.fromString("234tt")).toThrowError(/denom must be between 3 and 16 characters/i);
expect(() => fee_1.GasPrice.fromString("234ttttttttttttttttt")).toThrowError(/denom must be between 3 and 16 characters/i);
expect(() => fee_1.GasPrice.fromString("234ATOM")).toThrowError(/denom must only contain lower case letters a-z and digits 0-9/i);
// Checks details of <amount>
expect(() => fee_1.GasPrice.fromString("3.utkn")).toThrowError(/Fractional part missing/i);
expect(() => fee_1.GasPrice.fromString("..utkn")).toThrowError(/More than one separator found/i);
});
});
});
//# sourceMappingURL=fee.spec.js.map

@@ -138,7 +138,4 @@ "use strict";

const recipient = testutils_spec_1.makeRandomAddress();
const transferAmount = {
denom: "ucosm",
amount: "1234567",
};
const result = await client.sendTokens(recipient, [transferAmount]);
const amount = amino_1.coins(1234567, "ucosm");
const result = await client.sendTokens(recipient, amount);
successful = {

@@ -153,8 +150,3 @@ sender: testutils_spec_1.faucet.address0,

const recipient = testutils_spec_1.makeRandomAddress();
const transferAmount = [
{
denom: "ucosm",
amount: "123456700000000",
},
];
const amount = amino_1.coins(123456700000000, "ucosm");
const sendMsg = {

@@ -165,12 +157,7 @@ type: "cosmos-sdk/MsgSend",

to_address: recipient,
amount: transferAmount,
amount: amount,
},
};
const fee = {
amount: [
{
denom: "ucosm",
amount: "2000",
},
],
amount: amino_1.coins(2000, "ucosm"),
gas: "80000",

@@ -250,9 +237,4 @@ };

const recipient = testutils_spec_1.makeRandomAddress();
const transferAmount = [
{
denom: "ucosm",
amount: "1234567",
},
];
const result = await client.sendTokens(recipient, transferAmount);
const amount = amino_1.coins(1234567, "ucosm");
const result = await client.sendTokens(recipient, amount);
await utils_1.sleep(75); // wait until tx is indexed

@@ -259,0 +241,0 @@ const txDetails = await new lcdclient_1.LcdClient(testutils_spec_1.launchpad.endpoint).txById(result.transactionHash);

@@ -36,3 +36,3 @@ import { AminoMsg, Coin, OfflineAminoSigner, StdFee } from "@cosmjs/amino";

getAccount(address?: string): Promise<Account | undefined>;
sendTokens(recipientAddress: string, transferAmount: readonly Coin[], memo?: string): Promise<BroadcastTxResult>;
sendTokens(recipientAddress: string, amount: readonly Coin[], memo?: string): Promise<BroadcastTxResult>;
/**

@@ -39,0 +39,0 @@ * Gets account number and sequence from the API, creates a sign doc,

@@ -43,3 +43,3 @@ "use strict";

}
async sendTokens(recipientAddress, transferAmount, memo = "") {
async sendTokens(recipientAddress, amount, memo = "") {
const sendMsg = {

@@ -50,3 +50,3 @@ type: "cosmos-sdk/MsgSend",

to_address: recipientAddress,
amount: transferAmount,
amount: amount,
},

@@ -53,0 +53,0 @@ };

@@ -104,9 +104,3 @@ "use strict";

const client = new signingcosmosclient_1.SigningCosmosClient(testutils_spec_1.launchpad.endpoint, testutils_spec_1.faucet.address0, wallet);
// instantiate
const transferAmount = [
{
amount: "7890",
denom: "ucosm",
},
];
const amount = amino_1.coins(7890, "ucosm");
const beneficiaryAddress = testutils_spec_1.makeRandomAddress();

@@ -117,3 +111,3 @@ // no tokens here

// send
const result = await client.sendTokens(beneficiaryAddress, transferAmount, "for dinner");
const result = await client.sendTokens(beneficiaryAddress, amount, "for dinner");
cosmosclient_1.assertIsBroadcastTxSuccess(result);

@@ -125,3 +119,3 @@ const [firstLog] = result.logs;

utils_1.assert(after);
expect(after.balance).toEqual(transferAmount);
expect(after.balance).toEqual(amount);
});

@@ -128,0 +122,0 @@ });

{
"name": "@cosmjs/launchpad",
"version": "0.25.2",
"version": "0.25.3",
"description": "A client library for the Cosmos SDK 0.37 (cosmoshub-3), 0.38 and 0.39 (Launchpad)",

@@ -42,7 +42,7 @@ "contributors": [

"dependencies": {
"@cosmjs/amino": "^0.25.2",
"@cosmjs/crypto": "^0.25.2",
"@cosmjs/encoding": "^0.25.2",
"@cosmjs/math": "^0.25.2",
"@cosmjs/utils": "^0.25.2",
"@cosmjs/amino": "^0.25.3",
"@cosmjs/crypto": "^0.25.3",
"@cosmjs/encoding": "^0.25.3",
"@cosmjs/math": "^0.25.3",
"@cosmjs/utils": "^0.25.3",
"axios": "^0.21.1",

@@ -54,3 +54,3 @@ "fast-deep-equal": "^3.1.3"

},
"gitHead": "dab008f2f524aab5063fdda3ad510376425dc50a"
"gitHead": "ba7fd927d73ea56f85d8ff841282b88e4baeb718"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc