Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
WIP Finish possibe test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jacque006 committed Aug 23, 2021
1 parent 6c20fb3 commit efd9681
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 20 deletions.
1 change: 0 additions & 1 deletion contracts/Transfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
49 changes: 32 additions & 17 deletions test/slow/rollup.transfer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 })],
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion ts/client/features/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion ts/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit efd9681

Please sign in to comment.