Skip to content

Commit

Permalink
lint, fix some stuff, introduce new test etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
quasisamurai committed Sep 15, 2023
1 parent f1933a1 commit 72a2b93
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/helpers/cosmos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ export class CosmosWrapper {
}
}

async queryMaxTxsAllowed(): Promise<number> {
async queryMaxTxsAllowed(): Promise<string> {
try {
const req = await axios.get<InterchaintxsParamsResponse>(
`${this.sdk.url}/neutron/interchaintxs/params`,
Expand Down Expand Up @@ -695,8 +695,8 @@ export class WalletWrapper {
}
| string,
fee = {
gas_limit: Long.fromString('200000'),
amount: [{ denom: this.chain.denom, amount: '1000' }],
gas_limit: Long.fromString('300000'),
amount: [{ denom: this.chain.denom, amount: '1500' }],
},
sequence: number = this.wallet.account.sequence,
mode: cosmosclient.rest.tx.BroadcastTxMode = cosmosclient.rest.tx
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type PinCodesInfo = {
};

export type UpdateParamsInterchaintxsInfo = {
msg_submit_tx_max_messages: number;
msg_submit_tx_max_messages: string;
};
export type UpdateAdmin = {
sender: 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 @@ -172,6 +172,8 @@ export const NeutronContract = {
VESTING_INVESTORS: 'vesting_investors.wasm',
INVESTORS_VESTING_VAULT: 'investors_vesting_vault.wasm',
TOKENFACTORY: 'tokenfactory.wasm',
BEFORE_SEND_HOOK_TEST: 'before_send_hook_test.wasm',
NO100: 'no100.wasm',
};

export type MultiChoiceOption = {
Expand Down
2 changes: 1 addition & 1 deletion src/testcases/parallel/governance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ describe('Neutron / Governance', () => {
test('execute passed proposal', async () => {
await daoMember1.executeProposalWithAttempts(proposalId);
const paramAfter = await neutronChain.queryMaxTxsAllowed();
expect(paramAfter).toEqual("11");
expect(paramAfter).toEqual('11');
});
});

Expand Down
138 changes: 114 additions & 24 deletions src/testcases/parallel/tokenfactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,34 +190,114 @@ describe('Neutron / Tokenfactory', () => {

expect(balanceAfter).toEqual(9900);
});
});
test('create denom, set before send hook', async () => {
const codeId = await neutronAccount.storeWasm(
NeutronContract.BEFORE_SEND_HOOK_TEST,
);
expect(codeId).toBeGreaterThan(0);

test('create denom, set before send hook', async () => {
const denom = `test5`;
const res = await neutronAccount.instantiateContract(
codeId,
'{}',
'before_send_hook_test',
);
const contractAddress = res[0]._contract_address;

const data = await msgCreateDenom(
neutronAccount,
ownerWallet.address.toString(),
denom,
);
const newTokenDenom = getEventAttribute(
(data as any).events,
'create_denom',
'new_token_denom',
);
await msgSetBeforeSendHook(
neutronAccount,
ownerWallet.address.toString(),
newTokenDenom,
ownerWallet.address.toString(),
);
const denom = `test5`;

const hookAfter = await getBeforeSendHook(
neutronChain.sdk.url,
newTokenDenom,
);
const data = await msgCreateDenom(
neutronAccount,
ownerWallet.address.toString(),
denom,
);
const newTokenDenom = getEventAttribute(
(data as any).events,
'create_denom',
'new_token_denom',
);

expect(hookAfter.cosmwasm_address).toEqual(ownerWallet.address.toString());
await msgMintDenom(neutronAccount, ownerWallet.address.toString(), {
denom: newTokenDenom,
amount: '10000',
});

const balanceBefore = await neutronChain.queryDenomBalance(
ownerWallet.address.toString(),
newTokenDenom,
);

expect(balanceBefore).toEqual(10000);

await neutronAccount.msgSend(contractAddress, {
amount: '666',
denom: newTokenDenom,
});

const contractBalance = await neutronChain.queryDenomBalance(
contractAddress,
newTokenDenom,
);
expect(contractBalance).toEqual(666);

let queryBlock = await neutronChain.queryContract<{
block: { received: boolean };
}>(contractAddress, {
sudo_result_block_before: {},
});
console.log(queryBlock);

let queryTrack = await neutronChain.queryContract<{
track: { received: boolean };
}>(contractAddress, {
sudo_result_track_before: {},
});
console.log(queryTrack);

await msgSetBeforeSendHook(
neutronAccount,
ownerWallet.address.toString(),
newTokenDenom,
contractAddress,
);

const hookAfter = await getBeforeSendHook(
neutronChain.sdk.url,
newTokenDenom,
);
expect(hookAfter.cosmwasm_address).toEqual(contractAddress);

await neutronAccount.msgSend(contractAddress, {
amount: '1',
denom: newTokenDenom,
});

const contractBalanceAfter = await neutronChain.queryDenomBalance(
contractAddress,
newTokenDenom,
);
expect(contractBalanceAfter).toEqual(667);

const balanceAfter = await neutronChain.queryDenomBalance(
ownerWallet.address.toString(),
newTokenDenom,
);
expect(balanceAfter).toEqual(9333);

queryBlock = await neutronChain.queryContract<{
block: { received: boolean };
}>(contractAddress, {
sudo_result_block_before: {},
});

queryTrack = await neutronChain.queryContract<{
track: { received: boolean };
}>(contractAddress, {
sudo_result_track_before: {},
});

expect(queryTrack.track.received).toEqual(true);
expect(queryBlock.block.received).toEqual(true);
});
});

describe('wasmbindings', () => {
Expand Down Expand Up @@ -338,6 +418,16 @@ describe('Neutron / Tokenfactory', () => {
},
});
expect(res.contract_addr).toEqual(contractAddress);

await neutronAccount.executeContract(
contractAddress,
JSON.stringify({
set_before_send_hook: {
denom,
cosm_wasm_addr: '',
},
}),
);
});

test('change admin', async () => {
Expand Down

0 comments on commit 72a2b93

Please sign in to comment.