@cosmjs/stargate
Advanced tools
Comparing version 0.25.5 to 0.25.6
@@ -234,4 +234,6 @@ import { AminoMsg, Coin } from "@cosmjs/amino"; | ||
interface AminoHeight { | ||
readonly revision_number: string; | ||
readonly revision_height: string; | ||
/** 0 values must be omitted (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/core/02-client/types/client.pb.go#L252). */ | ||
readonly revision_number?: string; | ||
/** 0 values must be omitted (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/core/02-client/types/client.pb.go#L254). */ | ||
readonly revision_height?: string; | ||
} | ||
@@ -249,4 +251,15 @@ /** Transfers fungible tokens (i.e Coins) between ICS20 enabled chains */ | ||
readonly receiver: string; | ||
readonly timeout_height?: AminoHeight; | ||
readonly timeout_timestamp: string; | ||
/** | ||
* The timeout as a (revision_number, revision_height) pair. | ||
* | ||
* This fied is is non-optional (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/applications/transfer/types/tx.pb.go#L49). | ||
* In order to not set the timeout height, set it to {}. | ||
*/ | ||
readonly timeout_height: AminoHeight; | ||
/** | ||
* Timeout timestamp (in nanoseconds). The timeout is disabled when set to 0. | ||
* | ||
* 0 values must be omitted (https://github.com/cosmos/cosmos-sdk/blob/v0.42.7/x/ibc/applications/transfer/types/tx.pb.go#L52). | ||
*/ | ||
readonly timeout_timestamp?: string; | ||
}; | ||
@@ -253,0 +266,0 @@ } |
@@ -12,2 +12,14 @@ "use strict"; | ||
const long_1 = __importDefault(require("long")); | ||
function omitDefault(input) { | ||
if (typeof input === "string") { | ||
return input === "" ? undefined : input; | ||
} | ||
if (typeof input === "number") { | ||
return input === 0 ? undefined : input; | ||
} | ||
if (long_1.default.isLong(input)) { | ||
return input.isZero() ? undefined : input; | ||
} | ||
throw new Error(`Got unsupported type '${typeof input}'`); | ||
} | ||
function createDefaultTypes(prefix) { | ||
@@ -234,16 +246,19 @@ return { | ||
aminoType: "cosmos-sdk/MsgTransfer", | ||
toAmino: ({ sourcePort, sourceChannel, token, sender, receiver, timeoutHeight, timeoutTimestamp, }) => ({ | ||
source_port: sourcePort, | ||
source_channel: sourceChannel, | ||
token: token, | ||
sender: sender, | ||
receiver: receiver, | ||
timeout_height: timeoutHeight | ||
? { | ||
revision_height: timeoutHeight.revisionHeight.toString(), | ||
revision_number: timeoutHeight.revisionNumber.toString(), | ||
} | ||
: undefined, | ||
timeout_timestamp: timeoutTimestamp.toString(), | ||
}), | ||
toAmino: ({ sourcePort, sourceChannel, token, sender, receiver, timeoutHeight, timeoutTimestamp, }) => { | ||
var _a, _b, _c; | ||
return ({ | ||
source_port: sourcePort, | ||
source_channel: sourceChannel, | ||
token: token, | ||
sender: sender, | ||
receiver: receiver, | ||
timeout_height: timeoutHeight | ||
? { | ||
revision_height: (_a = omitDefault(timeoutHeight.revisionHeight)) === null || _a === void 0 ? void 0 : _a.toString(), | ||
revision_number: (_b = omitDefault(timeoutHeight.revisionNumber)) === null || _b === void 0 ? void 0 : _b.toString(), | ||
} | ||
: {}, | ||
timeout_timestamp: (_c = omitDefault(timeoutTimestamp)) === null || _c === void 0 ? void 0 : _c.toString(), | ||
}); | ||
}, | ||
fromAmino: ({ source_port, source_channel, token, sender, receiver, timeout_height, timeout_timestamp, }) => ({ | ||
@@ -257,7 +272,7 @@ sourcePort: source_port, | ||
? { | ||
revisionHeight: long_1.default.fromString(timeout_height.revision_height, true), | ||
revisionNumber: long_1.default.fromString(timeout_height.revision_number, true), | ||
revisionHeight: long_1.default.fromString(timeout_height.revision_height || "0", true), | ||
revisionNumber: long_1.default.fromString(timeout_height.revision_number || "0", true), | ||
} | ||
: undefined, | ||
timeoutTimestamp: long_1.default.fromString(timeout_timestamp, true), | ||
timeoutTimestamp: long_1.default.fromString(timeout_timestamp || "0", true), | ||
}), | ||
@@ -264,0 +279,0 @@ }, |
@@ -315,2 +315,64 @@ "use strict"; | ||
}); | ||
it("works for MsgTransfer with empty values", () => { | ||
const msg = { | ||
sourcePort: "testport", | ||
sourceChannel: "testchannel", | ||
token: proto_signing_1.coin(1234, "utest"), | ||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", | ||
timeoutHeight: { | ||
revisionHeight: long_1.default.UZERO, | ||
revisionNumber: long_1.default.UZERO, | ||
}, | ||
timeoutTimestamp: long_1.default.UZERO, | ||
}; | ||
const aminoMsg = new aminotypes_1.AminoTypes().toAmino({ | ||
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer", | ||
value: msg, | ||
}); | ||
const expected = { | ||
type: "cosmos-sdk/MsgTransfer", | ||
value: { | ||
source_port: "testport", | ||
source_channel: "testchannel", | ||
token: proto_signing_1.coin(1234, "utest"), | ||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", | ||
timeout_height: { | ||
revision_height: undefined, | ||
revision_number: undefined, | ||
}, | ||
timeout_timestamp: undefined, | ||
}, | ||
}; | ||
expect(aminoMsg).toEqual(expected); | ||
}); | ||
it("works for MsgTransfer with no height timeout", () => { | ||
const msg = { | ||
sourcePort: "testport", | ||
sourceChannel: "testchannel", | ||
token: proto_signing_1.coin(1234, "utest"), | ||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", | ||
timeoutHeight: undefined, | ||
timeoutTimestamp: long_1.default.UZERO, | ||
}; | ||
const aminoMsg = new aminotypes_1.AminoTypes().toAmino({ | ||
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer", | ||
value: msg, | ||
}); | ||
const expected = { | ||
type: "cosmos-sdk/MsgTransfer", | ||
value: { | ||
source_port: "testport", | ||
source_channel: "testchannel", | ||
token: proto_signing_1.coin(1234, "utest"), | ||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", | ||
timeout_height: {}, | ||
timeout_timestamp: undefined, | ||
}, | ||
}; | ||
expect(aminoMsg).toEqual(expected); | ||
}); | ||
it("works with custom type url", () => { | ||
@@ -607,2 +669,35 @@ const msg = { | ||
}); | ||
it("works for MsgTransfer with default values", () => { | ||
const aminoMsg = { | ||
type: "cosmos-sdk/MsgTransfer", | ||
value: { | ||
source_port: "testport", | ||
source_channel: "testchannel", | ||
token: proto_signing_1.coin(1234, "utest"), | ||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", | ||
timeout_height: { | ||
// revision_height omitted | ||
// revision_number omitted | ||
}, | ||
}, | ||
}; | ||
const msg = new aminotypes_1.AminoTypes().fromAmino(aminoMsg); | ||
const expectedValue = { | ||
sourcePort: "testport", | ||
sourceChannel: "testchannel", | ||
token: proto_signing_1.coin(1234, "utest"), | ||
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", | ||
receiver: "cosmos10dyr9899g6t0pelew4nvf4j5c3jcgv0r73qga5", | ||
timeoutHeight: { | ||
revisionHeight: long_1.default.UZERO, | ||
revisionNumber: long_1.default.UZERO, | ||
}, | ||
timeoutTimestamp: long_1.default.UZERO, | ||
}; | ||
expect(msg).toEqual({ | ||
typeUrl: "/ibc.applications.transfer.v1.MsgTransfer", | ||
value: expectedValue, | ||
}); | ||
}); | ||
it("works for custom type url", () => { | ||
@@ -609,0 +704,0 @@ const aminoMsg = { |
@@ -10,2 +10,3 @@ "use strict"; | ||
const utils_1 = require("@cosmjs/utils"); | ||
const long_1 = __importDefault(require("long")); | ||
const minimal_1 = __importDefault(require("protobufjs/minimal")); | ||
@@ -303,2 +304,40 @@ const build_1 = require("../../proto-signing/build"); | ||
}); | ||
describe("sendIbcTokens", () => { | ||
it("works with direct signing", async () => { | ||
testutils_spec_1.pendingWithoutSimapp(); | ||
const wallet = await proto_signing_1.DirectSecp256k1HdWallet.fromMnemonic(testutils_spec_1.faucet.mnemonic); | ||
const client = await signingstargateclient_1.SigningStargateClient.connectWithSigner(testutils_spec_1.simapp.tendermintUrl, wallet); | ||
const memo = "Cross-chain fun"; | ||
// both timeouts set | ||
{ | ||
const result = await client.sendIbcTokens(testutils_spec_1.faucet.address0, testutils_spec_1.faucet.address1, proto_signing_1.coin(1234, "ucosm"), "fooPort", "fooChannel", { revisionHeight: long_1.default.fromNumber(123), revisionNumber: long_1.default.fromNumber(456) }, Math.floor(Date.now() / 1000) + 60, memo); | ||
// CheckTx must pass but the execution must fail in DeliverTx due to invalid channel/port | ||
expect(stargateclient_1.isBroadcastTxFailure(result)).toEqual(true); | ||
} | ||
// no height timeout | ||
{ | ||
const result = await client.sendIbcTokens(testutils_spec_1.faucet.address0, testutils_spec_1.faucet.address1, proto_signing_1.coin(1234, "ucosm"), "fooPort", "fooChannel", undefined, Math.floor(Date.now() / 1000) + 60, memo); | ||
// CheckTx must pass but the execution must fail in DeliverTx due to invalid channel/port | ||
expect(stargateclient_1.isBroadcastTxFailure(result)).toEqual(true); | ||
} | ||
}); | ||
it("works with Amino signing", async () => { | ||
testutils_spec_1.pendingWithoutSimapp(); | ||
const wallet = await amino_1.Secp256k1HdWallet.fromMnemonic(testutils_spec_1.faucet.mnemonic); | ||
const client = await signingstargateclient_1.SigningStargateClient.connectWithSigner(testutils_spec_1.simapp.tendermintUrl, wallet); | ||
const memo = "Cross-chain fun"; | ||
// both timeouts set | ||
{ | ||
const result = await client.sendIbcTokens(testutils_spec_1.faucet.address0, testutils_spec_1.faucet.address1, proto_signing_1.coin(1234, "ucosm"), "fooPort", "fooChannel", { revisionHeight: long_1.default.fromNumber(123), revisionNumber: long_1.default.fromNumber(456) }, Math.floor(Date.now() / 1000) + 60, memo); | ||
// CheckTx must pass but the execution must fail in DeliverTx due to invalid channel/port | ||
expect(stargateclient_1.isBroadcastTxFailure(result)).toEqual(true); | ||
} | ||
// no height timeout | ||
{ | ||
const result = await client.sendIbcTokens(testutils_spec_1.faucet.address0, testutils_spec_1.faucet.address1, proto_signing_1.coin(1234, "ucosm"), "fooPort", "fooChannel", undefined, Math.floor(Date.now() / 1000) + 60, memo); | ||
// CheckTx must pass but the execution must fail in DeliverTx due to invalid channel/port | ||
expect(stargateclient_1.isBroadcastTxFailure(result)).toEqual(true); | ||
} | ||
}); | ||
}); | ||
describe("signAndBroadcast", () => { | ||
@@ -305,0 +344,0 @@ describe("direct mode", () => { |
{ | ||
"name": "@cosmjs/stargate", | ||
"version": "0.25.5", | ||
"version": "0.25.6", | ||
"description": "Utilities for Cosmos SDK 0.40", | ||
@@ -46,13 +46,13 @@ "contributors": [ | ||
"@confio/ics23": "^0.6.3", | ||
"@cosmjs/amino": "^0.25.5", | ||
"@cosmjs/encoding": "^0.25.5", | ||
"@cosmjs/math": "^0.25.5", | ||
"@cosmjs/proto-signing": "^0.25.5", | ||
"@cosmjs/stream": "^0.25.5", | ||
"@cosmjs/tendermint-rpc": "^0.25.5", | ||
"@cosmjs/utils": "^0.25.5", | ||
"@cosmjs/amino": "^0.25.6", | ||
"@cosmjs/encoding": "^0.25.6", | ||
"@cosmjs/math": "^0.25.6", | ||
"@cosmjs/proto-signing": "^0.25.6", | ||
"@cosmjs/stream": "^0.25.6", | ||
"@cosmjs/tendermint-rpc": "^0.25.6", | ||
"@cosmjs/utils": "^0.25.6", | ||
"long": "^4.0.0", | ||
"protobufjs": "~6.10.2" | ||
}, | ||
"gitHead": "9a0f120567021d51a8f37bcaf39cc3de4b7d9a3d" | ||
"gitHead": "2e52b1b540e737e3d49910efbdb97733d398ba54" | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3471391
48989
Updated@cosmjs/amino@^0.25.6
Updated@cosmjs/encoding@^0.25.6
Updated@cosmjs/math@^0.25.6
Updated@cosmjs/stream@^0.25.6
Updated@cosmjs/utils@^0.25.6