Skip to content

Commit

Permalink
Fix vesting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
assafmo committed Jun 11, 2023
1 parent 7acc51f commit f83f47d
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 23 deletions.
19 changes: 9 additions & 10 deletions src/secret_network_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -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,
Expand All @@ -203,6 +207,10 @@ import {
MsgSetAutoRestakeParams,
ProtoMsg,
} from "./tx";
import {
MsgToggleIbcSwitch,
MsgToggleIbcSwitchParams,
} from "./tx/emergency_button";
import { RaAuthenticate, RaAuthenticateParams } from "./tx/registration";
import {
MsgCreateVestingAccount,
Expand All @@ -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 */
Expand Down
102 changes: 89 additions & 13 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
base64TendermintPubkeyToValconsAddress,
coinsFromString,
gasToFee,
MsgCreateVestingAccount,
MsgDelegate,
MsgExecuteContract,
MsgExecuteContractResponse,
Expand All @@ -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";
Expand Down Expand Up @@ -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"),
});

Expand Down

0 comments on commit f83f47d

Please sign in to comment.