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

rescueeer test #151

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"test:tokenfactory": "jest -b src/testcases/parallel/tokenfactory",
"test:overrule": "jest -b src/testcases/run_in_band/overrule",
"test:tge:vesting_lp_vault": "jest -b src/testcases/parallel/tge.vesting_lp_vault",
"test:rescueeer": "jest -b src/testcases/parallel/rescueeer",
"gen:proto": "bash ./gen-proto.sh",
"lint": "eslint ./src",
"fmt": "eslint ./src --fix"
Expand Down
25 changes: 24 additions & 1 deletion src/helpers/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,12 @@ export class WalletWrapper {
codeId: number,
msg: string,
label: string,
admin: string = this.wallet.address.toString(),
): Promise<Array<Record<string, string>>> {
const msgInit = new cosmwasmproto.cosmwasm.wasm.v1.MsgInstantiateContract({
code_id: codeId + '',
sender: this.wallet.address.toString(),
admin: this.wallet.address.toString(),
admin: admin,
label,
msg: Buffer.from(msg),
});
Expand All @@ -495,6 +496,28 @@ export class WalletWrapper {
]);
}

async migrateContract(
contract: string,
migrateMsg: any,
codeId: number,
): Promise<InlineResponse20075TxResponse> {
const msg = new cosmwasmproto.cosmwasm.wasm.v1.MsgMigrateContract({
sender: this.wallet.address.toString(),
contract: contract,
code_id: codeId,
msg: Buffer.from(JSON.stringify(migrateMsg)),
});
const res = await this.execTx(
{
amount: [{ denom: NEUTRON_DENOM, amount: '250000' }],
gas_limit: Long.fromString('60000000'),
},
[msg],
);

return res?.tx_response;
}

async executeContract(
contract: string,
msg: string,
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ export const NeutronContract = {
ASTRO_WHITELIST: '../contracts_thirdparty/astroport_whitelist.wasm',
VESTING_LP: 'vesting_lp.wasm',
VESTING_LP_VAULT: 'vesting_lp_vault.wasm',
RESCUEEER: 'rescueeer.wasm',
MULTISIG: '../contracts_thirdparty/cw3_fixed_multisig.wasm',
};

export type MultiChoiceOption = {
Expand Down
187 changes: 187 additions & 0 deletions src/testcases/parallel/rescueeer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
import { TestStateLocalCosmosTestNet } from '../common_localcosmosnet';
import {
CosmosWrapper,
NEUTRON_DENOM,
WalletWrapper,
wrapMsg,
} from '../../helpers/cosmos';
import { NeutronContract } from '../../helpers/types';
import { wait } from '../../helpers/wait';

describe('Rescueer', () => {
let testState: TestStateLocalCosmosTestNet;
let neutronChain: CosmosWrapper;
let neutronAccount: WalletWrapper;

beforeAll(async () => {
testState = new TestStateLocalCosmosTestNet();
await testState.init();
neutronChain = new CosmosWrapper(
testState.sdk1,
testState.blockWaiter1,
NEUTRON_DENOM,
);
neutronAccount = new WalletWrapper(
neutronChain,
testState.wallets.qaNeutron.genQaWal1,
);
});

describe('rescueer', () => {
test('multisig', async () => {
const multisigCodeId = await neutronAccount.storeWasm(
NeutronContract.MULTISIG,
);
const reflectCodeId = await neutronAccount.storeWasm(
NeutronContract.REFLECT,
);
const rescuerCodeId = await neutronAccount.storeWasm(
NeutronContract.RESCUEEER,
);
const contractCodeId = await neutronAccount.storeWasm(
NeutronContract.IBC_TRANSFER,
);
expect(multisigCodeId).toBeGreaterThan(0);
expect(reflectCodeId).toBeGreaterThan(0);
expect(rescuerCodeId).toBeGreaterThan(0);
expect(contractCodeId).toBeGreaterThan(0);

const multisigRes = await neutronAccount.instantiateContract(
multisigCodeId,
JSON.stringify({
voters: [
{
addr: neutronAccount.wallet.address.toString(),
weight: 1,
},
],
threshold: { absolute_count: { weight: 1 } },
max_voting_period: { height: 1000 },
}),
'multisig',
);
const multisigAddress = multisigRes[0]._contract_address;
expect(multisigAddress).toBeDefined();
expect(multisigAddress).not.toEqual('');

const dao = (await neutronChain.getChainAdmins())[0];
const currentTimestamp = Math.floor(Date.now() / 1000);
const eol = currentTimestamp + 30;
const rescuerRes = await neutronAccount.instantiateContract(
rescuerCodeId,
JSON.stringify({
owner: multisigAddress,
true_admin: dao,
eol: eol,
}),
'rescueeer',
);
const rescuerAddress = rescuerRes[0]._contract_address;
expect(rescuerAddress).toBeDefined();
expect(rescuerAddress).not.toEqual('');

const contractRes = await neutronAccount.instantiateContract(
contractCodeId,
'{}',
'ibc_transfer',
rescuerAddress,
);
const contractAddress = contractRes[0]._contract_address;
expect(contractAddress).toBeDefined();
expect(contractAddress).not.toEqual('');

const currentAdmin = (
await neutronChain.getContractInfo(contractAddress)
)['contract_info']['admin'];
expect(currentAdmin).toBe(rescuerAddress);

const rescuerExecMigrateMsg = {
execute: {
msgs: [
{
wasm: {
migrate: {
contract_addr: contractAddress,
msg: wrapMsg({}),
new_code_id: reflectCodeId,
},
},
},
],
},
};

await expect(
neutronAccount.executeContract(
rescuerAddress,
JSON.stringify(rescuerExecMigrateMsg),
),
).rejects.toThrow(/Unauthorized/);
await neutronAccount.executeContract(
multisigAddress,
JSON.stringify({
propose: {
title: '123',
description: '234',
msgs: [
{
wasm: {
execute: {
contract_addr: rescuerAddress,
msg: wrapMsg(rescuerExecMigrateMsg),
funds: [],
},
},
},
],
},
}),
);

await neutronAccount.executeContract(
multisigAddress,
JSON.stringify({
execute: {
proposal_id: 1,
},
}),
);

const newCodeId = parseInt(
(await neutronChain.getContractInfo(contractAddress))['contract_info'][
'code_id'
],
);
expect(newCodeId).toBe(reflectCodeId);

expect(Math.floor(Date.now() / 1000)).toBeLessThan(eol - 10);

await expect(
neutronAccount.executeContract(
rescuerAddress,
JSON.stringify({
transfer_admin: {
address: contractAddress,
},
}),
),
).rejects.toThrow(/End of life haven't reached yet/);

await wait(eol - Math.floor(Date.now() / 1000) + 3);

await neutronAccount.executeContract(
rescuerAddress,
JSON.stringify({
transfer_admin: {
address: contractAddress,
},
}),
);

const newAdmin = (await neutronChain.getContractInfo(contractAddress))[
'contract_info'
]['admin'];
expect(newAdmin).toBe(dao);
});
});
});