diff --git a/src/secret_network_client.ts b/src/secret_network_client.ts index 937fe5d1..2f18a7ea 100644 --- a/src/secret_network_client.ts +++ b/src/secret_network_client.ts @@ -148,6 +148,10 @@ import { Service as TxService, } from "./grpc_gateway/cosmos/tx/v1beta1/service.pb"; import { Tx as TxPb } from "./grpc_gateway/cosmos/tx/v1beta1/tx.pb"; +import { + ContinuousVestingAccount, + DelayedVestingAccount, +} from "./grpc_gateway/cosmos/vesting/v1beta1/vesting.pb"; import { TxMsgData } from "./protobuf/cosmos/base/abci/v1beta1/abci"; import { LegacyAminoPubKey } from "./protobuf/cosmos/crypto/multisig/keys"; import { PubKey } from "./protobuf/cosmos/crypto/secp256k1/keys"; @@ -167,6 +171,7 @@ import { AuthzQuerier } from "./query/authz"; import { BankQuerier } from "./query/bank"; import { ComputeQuerier, bytesToAddress } from "./query/compute"; import { DistributionQuerier } from "./query/distribution"; +import { EmergencyButtonQuerier } from "./query/emergency_button"; import { EvidenceQuerier } from "./query/evidence"; import { FeegrantQuerier } from "./query/feegrant"; import { GovQuerier } from "./query/gov"; @@ -185,7 +190,6 @@ import { SlashingQuerier } from "./query/slashing"; import { StakingQuerier } from "./query/staking"; import { TendermintQuerier } from "./query/tendermint"; import { UpgradeQuerier } from "./query/upgrade"; -import { EmergencyButtonQuerier } from "./query/emergency_button"; import { AminoMsg, Msg, @@ -203,6 +207,10 @@ import { MsgSetAutoRestakeParams, ProtoMsg, } from "./tx"; +import { + MsgToggleIbcSwitch, + MsgToggleIbcSwitchParams, +} from "./tx/emergency_button"; import { RaAuthenticate, RaAuthenticateParams } from "./tx/registration"; import { MsgCreateVestingAccount, @@ -221,15 +229,6 @@ import { isSignDoc, isSignDocCamelCase, } from "./wallet_amino"; -import { - MsgToggleIbcSwitch, - MsgToggleIbcSwitchParams, -} from "./tx/emergency_button"; -import { - BaseVestingAccount, - ContinuousVestingAccount, - DelayedVestingAccount, -} from "./grpc_gateway/cosmos/vesting/v1beta1/vesting.pb"; export type CreateClientOptions = { /** A URL to the API service, also known as LCD, REST API or gRPC-gateway, by default on port 1317 */ diff --git a/test/test.ts b/test/test.ts index 1cb74db5..ef727722 100644 --- a/test/test.ts +++ b/test/test.ts @@ -6,6 +6,7 @@ import { base64TendermintPubkeyToValconsAddress, coinsFromString, gasToFee, + MsgCreateVestingAccount, MsgDelegate, MsgExecuteContract, MsgExecuteContractResponse, @@ -26,6 +27,7 @@ import { validateAddress, validatorAddressToSelfDelegatorAddress, VoteOption, + Wallet, } from "../src"; import { BaseAccount } from "../src/grpc_gateway/cosmos/auth/v1beta1/auth.pb"; import { Proposal } from "../src/grpc_gateway/cosmos/gov/v1beta1/gov.pb"; @@ -3057,36 +3059,110 @@ test("url with trailing slashes", async () => { expect(Number(res.block?.header?.height)).toBeGreaterThan(0); }); -describe.skip("tx.vesting", () => { - test("MsgCreateVestingAccount & send tx form a vesting account", async () => { +describe.skip("vesting", () => { + test("MsgCreateVestingAccount & send tx form ContinuousVestingAccount", async () => { const { secretjsProto: secretjsProto0 } = accounts[0]; - let tx = await secretjsProto0.tx.vesting.createVestingAccount({ - from_address: accounts[0].address, - to_address: accounts[1].address, + // Test MsgCreateVestingAccount + + const newWallet = new Wallet(); + + let tx = await secretjsProto0.tx.broadcast([ + new MsgCreateVestingAccount({ + from_address: accounts[0].address, + to_address: newWallet.address, // to_address must be a new address + amount: coinsFromString("1uscrt"), + end_time: String(Math.floor(Date.now() / 1000 + 10 * 60)), // 10 minutes + delayed: false, + }), + new MsgSend({ + from_address: accounts[0].address, + to_address: newWallet.address, + amount: coinsFromString("10000000uscrt"), + }), + ]); + + if (tx.code !== TxResultCode.Success) { + console.error(tx.rawLog); + } + expect(tx.code).toBe(TxResultCode.Success); + + let { account } = await secretjsProto0.query.auth.account({ + address: newWallet.address, + }); + + expect(account!["@type"]).toBe( + "/cosmos.vesting.v1beta1.ContinuousVestingAccount", + ); + + // Test sending txs from ContinuousVestingAccount + + const secretjsNewWallet = new SecretNetworkClient({ + url: chain1LCD, + chainId: "secretdev-1", + wallet: newWallet, + walletAddress: newWallet.address, + }); + + tx = await secretjsNewWallet.tx.bank.send({ + from_address: newWallet.address, + to_address: accounts[0].address, amount: coinsFromString("1uscrt"), - end_time: String(Math.floor(Date.now() / 1000 + 10 * 60)), // 10 minutes - delayed: false, }); if (tx.code !== TxResultCode.Success) { console.error(tx.rawLog); } expect(tx.code).toBe(TxResultCode.Success); + }); + + test("MsgCreateVestingAccount & send tx form DelayedVestingAccount", async () => { + const { secretjsProto: secretjsProto0 } = accounts[0]; + + // Test MsgCreateVestingAccount + + const newWallet = new Wallet(); + + let tx = await secretjsProto0.tx.broadcast([ + new MsgCreateVestingAccount({ + from_address: accounts[0].address, + to_address: newWallet.address, // to_address must be a new address + amount: coinsFromString("1uscrt"), + end_time: String(Math.floor(Date.now() / 1000 + 10 * 60)), // 10 minutes + delayed: true, + }), + new MsgSend({ + from_address: accounts[0].address, + to_address: newWallet.address, + amount: coinsFromString("10000000uscrt"), + }), + ]); + + if (tx.code !== TxResultCode.Success) { + console.error(tx.rawLog); + } + expect(tx.code).toBe(TxResultCode.Success); let { account } = await secretjsProto0.query.auth.account({ - address: accounts[1].address, + address: newWallet.address, }); expect(account!["@type"]).toBe( - "/cosmos.vesting.v1beta1.BaseVestingAccount", + "/cosmos.vesting.v1beta1.DelayedVestingAccount", ); - const { secretjs: secretjs1 } = accounts[1]; + // Test sending txs from DelayedVestingAccount + + const secretjsNewWallet = new SecretNetworkClient({ + url: chain1LCD, + chainId: "secretdev-1", + wallet: newWallet, + walletAddress: newWallet.address, + }); - tx = await secretjs1.tx.bank.send({ - from_address: accounts[1].address, - to_address: accounts[1].address, + tx = await secretjsNewWallet.tx.bank.send({ + from_address: newWallet.address, + to_address: accounts[0].address, amount: coinsFromString("1uscrt"), });