Skip to content

Commit

Permalink
test(core): add simulation test for SigningArchwayClient
Browse files Browse the repository at this point in the history
  • Loading branch information
pyncz committed Jul 5, 2024
1 parent b866aa3 commit 30bb25c
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/arch3-core/src/signingarchwayclient.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Coin, addCoins, coin, coins } from '@cosmjs/amino';
import { AccountData, DirectSecp256k1HdWallet, decodeTxRaw, makeCosmoshubPath } from '@cosmjs/proto-signing';
import { GasPrice, StdFee, calculateFee } from '@cosmjs/stargate';
import { Fee } from 'cosmjs-types/cosmos/tx/v1beta1/tx';

import { ContractMetadata, SigningArchwayClient, SigningArchwayClientOptions } from '.';

Expand Down Expand Up @@ -442,5 +443,43 @@ describe('SigningArchwayClient', () => {
client.disconnect();
});
});

describe('simulation', () => {
it('granter and payer are passed to the `simulate` call', async () => {
const [wallet, accounts] = await getWalletWithAccounts();
const client = await SigningArchwayClient.connectWithSigner(archwayd.endpoint, wallet, clientOptions);

// Setup spy function; spy on `Fee` constructor to be called within the `simulate` instead of `simulate` itself
// to be able to verify fee params used in the simulation tx instead of just number of gas
const feeSpy = jest.spyOn(Fee, 'fromPartial');

const sender = accounts[2].address;
const granter = accounts[4].address;
const payer = accounts[5].address;
const msgs = [];
const memo = '';

try {
await client.calculateFee(
sender,
msgs,
memo,
1.5,
granter,
payer,
);
} catch (e) {
// Don't panic even if failed, as we want to check the arguments used
// inside the simulation rather than the final result
}

expect(feeSpy).toHaveBeenCalledWith({
granter,
payer,
});

client.disconnect();
});
});
});
});

0 comments on commit 30bb25c

Please sign in to comment.