Skip to content

Commit

Permalink
fixup! fixup! test: add test for receivers account precheck
Browse files Browse the repository at this point in the history
Signed-off-by: Nadezhda Popova <[email protected]>
  • Loading branch information
nadezhdapopovaa committed Dec 12, 2024
1 parent 62b7885 commit 12cdbe7
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions packages/relay/tests/lib/precheck.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,4 +654,50 @@ describe('Precheck', async function () {
expect(error.code).to.equal(predefined.UNSUPPORTED_TRANSACTION_TYPE.code);
});
});

describe('receiverAccount', async function () {
let parsedTx: Transaction;
let mirrorAccountTo: any;
const defaultNonce: number = 4;
const toAddress = ethers.Wallet.createRandom().address;

before(async () => {
const wallet = ethers.Wallet.createRandom();
const signed = await wallet.signTransaction({
...defaultTx,
from: wallet.address,
to: toAddress,
nonce: defaultNonce,
});

parsedTx = ethers.Transaction.from(signed);
});

it('should fail with signature required error', async function () {
mirrorAccountTo = {
receiver_sig_required: true,
};

mock.onGet(`accounts/${parsedTx.to}${transactionsPostFix}`).reply(200, mirrorAccountTo);

try {
await precheck.receiverAccount(parsedTx, requestDetails);
expectedError();
} catch (e: any) {
expect(e).to.exist;
expect(e.code).to.eq(-32000);
expect(e).to.eql(predefined.RECEIVER_SIGNATURE_REQUIRED);
}
});

it('should accept check if signature required is set to false', async function () {
mirrorAccountTo = {
receiver_sig_required: false,
};

mock.onGet(`accounts/${parsedTx.to}${transactionsPostFix}`).reply(200, mirrorAccountTo);

expect(async () => await precheck.receiverAccount(parsedTx, requestDetails)).not.to.throw;
});
});
});

0 comments on commit 12cdbe7

Please sign in to comment.