Skip to content

Commit

Permalink
feat: vesting account testing
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Oct 18, 2023
1 parent 4ee9189 commit aa94cdc
Showing 1 changed file with 88 additions and 34 deletions.
122 changes: 88 additions & 34 deletions integration-tests/src/modules/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getMnemonics } from "../helpers/mnemonics";
import { getLCDClient } from "../helpers/lcd.connection";
import { Coins, MnemonicKey, MsgCreateVestingAccount} from "@terra-money/feather.js";
import { ContinuousVestingAccount, Coins, MnemonicKey, MsgCreateVestingAccount } from "@terra-money/feather.js";
import moment from "moment";
import { blockInclusion } from "../helpers/const";

Expand Down Expand Up @@ -34,38 +34,39 @@ describe("Auth Module (https://github.com/terra-money/cosmos-sdk/tree/release/v0
try {
// Query genesis vesting account info
const vestAccAddr = accounts.genesisVesting.accAddress("terra");
const accountInfo = await LCD.chain1.auth.accountInfo(vestAccAddr);
const vestAcc = (await LCD.chain1.auth.accountInfo(vestAccAddr)) as ContinuousVestingAccount;

expect(accountInfo.toData())
.toMatchObject({
"@type": "/cosmos.vesting.v1beta1.ContinuousVestingAccount",
"base_vesting_account": {
"@type": "/cosmos.vesting.v1beta1.BaseVestingAccount",
"base_account": {
"@type": "/cosmos.auth.v1beta1.BaseAccount",
"account_number": "3",
"address": "terra1gyf58rxglrzp343d4wkw7vzlcw6d8knp2qmg0t",
"pub_key": {
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "A4VkfYoPDY1Ku7PxPU5LZDYdQE3OS/liDNmCJxsVvQxW",
},
"sequence": "1",
},
"delegated_free": [],
"delegated_vesting": [{
"amount": "10000000000",
"denom": "uluna",
},
],
"end_time": "1797557044",
"original_vesting": [{
"amount": "10000000000",
"denom": "uluna",
},
],
},
"start_time": "1697557021",
});
// Validate the instance of the object
expect(vestAcc)
.toBeInstanceOf(ContinuousVestingAccount);
// Validate the vesting start has been set in the past
expect(vestAcc.start_time)
.toBeLessThan(moment().unix());
// Validate the vesting end has been set in the past
expect(vestAcc.base_vesting_account.end_time)
.toBeGreaterThan(moment().unix());
// Validate the original vesting and delegated vesting
expect(vestAcc.base_vesting_account.original_vesting)
.toStrictEqual(Coins.fromString("10000000000uluna"));
expect(vestAcc.base_vesting_account.delegated_vesting)
.toStrictEqual(Coins.fromString("10000000000uluna"));

// Validate other params from base account
expect(vestAcc.base_vesting_account.base_account.address)
.toBe(vestAccAddr);
expect(vestAcc.getAccountNumber())
.toBe(3);
expect(vestAcc.getPublicKey())
.toBeNull();
expect(vestAcc.getSequenceNumber())
.toBe(0);

// Query the non-vested account balance
const vestAccBalance = await LCD.chain1.bank.balance(vestAccAddr);

// Validate the unlocked balance is still available
expect(vestAccBalance[0])
.toStrictEqual(Coins.fromString("990000000000uluna"));
}
catch (e) {
expect(e).toBeUndefined();
Expand All @@ -90,10 +91,63 @@ describe("Auth Module (https://github.com/terra-money/cosmos-sdk/tree/release/v0
let result = await LCD.chain1.tx.broadcastSync(tx, "test-1");
await blockInclusion();
let txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1");
console.log(JSON.stringify(txResult))
expect(JSON.parse(txResult.raw_log)[0].events)
.toEqual([{
"type": "message",
"attributes": [{
"key": "action",
"value": "/cosmos.vesting.v1beta1.MsgCreateVestingAccount"
}, {
"key": "sender",
"value": vestAccAddr1
}, {
"key": "module",
"value": "vesting"
}]
},
{
"type": "coin_spent",
"attributes": [{
"key": "spender",
"value": vestAccAddr1
}, {
"key": "amount",
"value": "100uluna"
}]
},
{
"type": "coin_received",
"attributes": [{
"key": "receiver",
"value": randomAccountAddress
}, {
"key": "amount",
"value": "100uluna"
}]
},
{
"type": "transfer",
"attributes": [{
"key": "recipient",
"value": randomAccountAddress
}, {
"key": "sender",
"value": vestAccAddr1
}, {
"key": "amount",
"value": "100uluna"
}]
},
{
"type": "message",
"attributes": [{
"key": "sender",
"value": vestAccAddr1
}]
}
])
}
catch (e) {
console.log(JSON.stringify(e))
expect(e).toBeUndefined();
}
});
Expand Down

0 comments on commit aa94cdc

Please sign in to comment.