Skip to content

Commit

Permalink
fix(contract): use fallback account if onAccount not provided
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jun 28, 2023
1 parent 7509795 commit 9033cd7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
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
2 changes: 1 addition & 1 deletion test/integration/Middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('MiddlewareSubscriber', () => {
},
mdwGensPerMinute: res.mdwGensPerMinute,
mdwHeight: res.mdwHeight,
mdwLastMigration: 20230519120000,
mdwLastMigration: res.mdwLastMigration,
mdwRevision: res.mdwRevision,
mdwSynced: true,
mdwSyncing: true,
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 9033cd7

Please sign in to comment.