From efd96815e5828a396c555ca6b5d3e08f2c904a5b Mon Sep 17 00:00:00 2001 From: Jacob Caban-Tomski Date: Mon, 23 Aug 2021 16:01:13 -0600 Subject: [PATCH] WIP Finish possibe test cases --- contracts/Transfer.sol | 1 - test/slow/rollup.transfer.test.ts | 49 ++++++++++++++++++++----------- ts/client/features/transfer.ts | 2 +- ts/tx.ts | 2 +- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/contracts/Transfer.sol b/contracts/Transfer.sol index 13ee5e19..3387678b 100644 --- a/contracts/Transfer.sol +++ b/contracts/Transfer.sol @@ -37,7 +37,6 @@ contract Transfer { uint256 fees = 0; // tokenID should be the same for all states in this commit - // TODO if they are not, should we return an error result that indicates that? uint256 tokenID = proofs[0].state.tokenID; Tx.Transfer memory _tx; diff --git a/test/slow/rollup.transfer.test.ts b/test/slow/rollup.transfer.test.ts index afca535e..495dcc55 100644 --- a/test/slow/rollup.transfer.test.ts +++ b/test/slow/rollup.transfer.test.ts @@ -24,6 +24,16 @@ const DOMAIN = hexToUint8Array( "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" ); +class BadCompressionTxTransfer extends TxTransfer { + constructor() { + super(0, 0, BigNumber.from(0), BigNumber.from(0), 0); + } + + public encode(): string { + return "0x1337"; + } +} + describe("Rollup Transfer", async function() { const tokenID = 1; const initialBalance = USDT.fromHumanValue("55.6").l2Value; @@ -197,22 +207,27 @@ describe("Rollup Transfer", async function() { ], expectedResult: Result.NotEnoughTokenBalance }, - /** - * TODO Implement cases for: - * - Result.BadFromTokenID - * - Result.BadToTokenID - */ - - /** - * TODO In this PR investigate if we can implment test cases for: - * - Result.BadSignature - * - Result.MismatchedAmount - * - Result.BadWithdrawRoot - * - Result.BadCompression - * - Result.TooManyTx - * - Result.BadPrecompileCall - */ - + { + description: "bad compression (encoding)", + txsFactory: () => { + const tx = new BadCompressionTxTransfer(); + tx.signature = users.getUser(0).sign(tx); + return [tx]; + }, + expectedResult: Result.BadCompression + }, + { + description: `too many txs in commit (> ${TESTING_PARAMS.MAX_TXS_PER_COMMIT})`, + txsFactory: () => { + const lenTooManyTxs = TESTING_PARAMS.MAX_TXS_PER_COMMIT + 1; + const txs = []; + while (txs.length < lenTooManyTxs) { + txs.push(txFactory({})); + } + return txs; + }, + expectedResult: Result.TooManyTx + }, { description: "non-existant fromIndex", txsFactory: () => [txFactory({ fromIndex: users.size + 1 })], @@ -224,7 +239,7 @@ describe("Rollup Transfer", async function() { expectedResult: Result.BadToIndex } ].forEach(({ description, txsFactory, expectedResult }) => { - it(`dispute and rollback a bad batch with l2 tx with ${description}`, async function() { + it(`dispute and rollback a bad batch with l2 tx(s) with ${description}`, async function() { const { rollup } = contracts; const txs = txsFactory(); diff --git a/ts/client/features/transfer.ts b/ts/client/features/transfer.ts index 88217bae..6f7dbe13 100644 --- a/ts/client/features/transfer.ts +++ b/ts/client/features/transfer.ts @@ -219,7 +219,7 @@ type TransactionBundle = { export function getAggregateSig(txs: OffchainTx[]): solG1 { const signatures = []; for (const tx of txs) { - if (!tx.signature) throw new Error(`tx has no signautre ${tx}`); + if (!tx.signature) throw new Error(`tx has no signature ${tx}`); signatures.push(tx.signature); } return aggregate(signatures).sol; diff --git a/ts/tx.ts b/ts/tx.ts index 61985778..67d0b795 100644 --- a/ts/tx.ts +++ b/ts/tx.ts @@ -57,7 +57,7 @@ export function serialize(txs: Tx[]): string { export function getAggregateSig(txs: SignableTx[]): solG1 { const signatures = []; for (const tx of txs) { - if (!tx.signature) throw new Error(`tx has no signautre ${tx}`); + if (!tx.signature) throw new Error(`tx has no signature ${tx}`); signatures.push(tx.signature); } return aggregate(signatures).sol;