Skip to content

Commit

Permalink
Merge pull request #1851 from aeternity/feature/fix-fallback-account
Browse files Browse the repository at this point in the history
fix(contract): use fallback account if `onAccount` not provided
  • Loading branch information
davidyuk authored Jul 4, 2023
2 parents 4e70e21 + 9033cd7 commit 2e5e20e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/contract/Contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ class Contract<M extends ContractMethodsBase> {
const useFallbackAccount = callStatic === true && (
(error instanceof TypeError && error.message === 'Account should be an address (ak-prefixed string), or instance of AccountBase, got undefined instead')
|| (error instanceof NoWalletConnectedError)
|| (error instanceof InternalError && error.message === 'Use fallback account')
);
if (!useFallbackAccount) throw error;
callerId = DRY_RUN_ACCOUNT.pub;
Expand Down
8 changes: 8 additions & 0 deletions test/integration/contract-aci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ describe('Contract instance', () => {
expect(res.tx.fee).to.be.equal('182000000000000');
});

it('calls with fallback account if onAccount is not provided', async () => {
const account = testContract.$options.onAccount;
delete testContract.$options.onAccount;
const res = await testContract.intFn(2);
expect(res.decodedResult).to.be.equal(2n);
testContract.$options.onAccount = account;
});

it('calls on chain', async () => {
const res = await testContract.intFn(2, { callStatic: false });
expect(res.decodedResult).to.be.equal(2n);
Expand Down

0 comments on commit 2e5e20e

Please sign in to comment.