Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(v2.7): authz test to reproduce feeshare bug #213

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions integration-tests/src/modules/authz.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { getMnemonics } from "../helpers/mnemonics";
import { getLCDClient } from "../helpers/lcd.connection";
import { StakeAuthorization, MsgGrantAuthorization, AuthorizationGrant, Coin, MsgExecAuthorized, MsgDelegate } from "@terra-money/feather.js";
import { AuthorizationType } from "@terra-money/terra.proto/cosmos/staking/v1beta1/authz";
import moment from "moment";
import { blockInclusion } from "../helpers/const";

describe("Authz Module (https://github.com/terra-money/cosmos-sdk/tree/release/v0.47.x/x/authz)", () => {
const LCD = getLCDClient();
const accounts = getMnemonics();
// Accounts used in chain2, which means that
// will not cause conflicts with txs nonces
const granterWallet = LCD.chain2.wallet(accounts.feeshareMnemonic);
const granteeWallet = LCD.chain2.wallet(accounts.pobMnemonic);
const granterAddr = accounts.feeshareMnemonic.accAddress("terra");
const granteeAddr = accounts.pobMnemonic.accAddress("terra");
const val2Addr = accounts.val2.valAddress("terra");

test('Must register the granter', async () => {
let tx = await granterWallet.createAndSignTx({
msgs: [new MsgDelegate(
granterAddr,
val2Addr,
Coin.fromString("1000000uluna"),
),new MsgGrantAuthorization(
granterAddr,
granteeAddr,
new AuthorizationGrant(
new StakeAuthorization(
AuthorizationType.AUTHORIZATION_TYPE_DELEGATE,
Coin.fromString("1000000uluna"),
),
moment().add(1, "hour").toDate(),
),
)],
chainID: "test-2",
});
let result = await LCD.chain2.tx.broadcastSync(tx, "test-2");
await blockInclusion();

// Check the MsgGrantAuthorization executed as expected
let txResult = await LCD.chain2.tx.txInfo(result.txhash, "test-2") as any;
expect(txResult.logs[0].events)
.toStrictEqual([{
"type": "message",
"attributes": [{
"key": "action",
"value": "/cosmos.authz.v1beta1.MsgGrant"
}, {
"key": "sender",
"value": "terra120rzk7n6cd2vufkmwrat34adqh0rgca9tkyfe5"
}, {
"key": "module",
"value": "authz"
}]
}, {
"type": "cosmos.authz.v1beta1.EventGrant",
"attributes": [{
"key": "grantee",
"value": "\"terra1v0eee20gjl68fuk0chyrkch2z7suw2mhg3wkxf\""
}, {
"key": "granter",
"value": "\"terra120rzk7n6cd2vufkmwrat34adqh0rgca9tkyfe5\""
}, {
"key": "msg_type_url",
"value": "\"/cosmos.staking.v1beta1.MsgDelegate\""
}]
}]);
});

describe("Grantee must execute", () => {
test("delegation on belhalf of granter", async () => {
try {
let tx = await granteeWallet.createAndSignTx({
msgs: [new MsgExecAuthorized(
granteeAddr,
[new MsgDelegate(
granterAddr,
val2Addr,
Coin.fromString("1000000uluna"),
)]
)],
chainID: "test-2",
});
let result = await LCD.chain2.tx.broadcastSync(tx, "test-2");
await blockInclusion();

console.log(result);
}
catch (e) {
console.log(e)
}
});
})
});
Loading