Skip to content

Commit

Permalink
Merge branch 'master' into merge-pr-290
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Mar 1, 2021
2 parents 64a8f95 + 5f47fe9 commit caee29d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/bin/zksync_api/src/api_server/tx_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,17 @@ impl TxSender {
let tx_fee_info = tx.tx.get_fee_info();

if let Some((tx_type, token, address, provided_fee)) = tx_fee_info {
// Save the transaction type before moving on to the next one, otherwise
// the total fee won't get affected by it.
transaction_types.push((tx_type, address));

if provided_fee == BigUint::zero() {
continue;
}
let fee_allowed =
Self::token_allowed_for_fees(self.ticker_requests.clone(), token.clone())
.await?;

transaction_types.push((tx_type, address));

// In batches, transactions with non-popular token are allowed to be included, but should not
// used to pay fees. Fees must be covered by some more common token.
if !fee_allowed && provided_fee != 0u64.into() {
Expand Down
1 change: 1 addition & 0 deletions core/tests/ts-tests/tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe(`ZkSync integration tests (token: ${token}, transport: ${transport})`,
await tester.testBatch(alice, bob, token, TX_AMOUNT);
await tester.testIgnoredBatch(alice, bob, token, TX_AMOUNT);
await tester.testRejectedBatch(alice, bob, token, TX_AMOUNT);
await tester.testInvalidFeeBatch(alice, bob, token, TX_AMOUNT);
});

step('should test batch-builder', async () => {
Expand Down
38 changes: 38 additions & 0 deletions core/tests/ts-tests/tests/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare module './tester' {
testBatch(from: Wallet, to: Wallet, token: TokenLike, amount: BigNumber): Promise<void>;
testIgnoredBatch(from: Wallet, to: Wallet, token: TokenLike, amount: BigNumber): Promise<void>;
testRejectedBatch(from: Wallet, to: Wallet, token: TokenLike, amount: BigNumber): Promise<void>;
testInvalidFeeBatch(from: Wallet, to: Wallet, token: TokenLike, amount: BigNumber): Promise<void>;
}
}

Expand Down Expand Up @@ -141,3 +142,40 @@ Tester.prototype.testRejectedBatch = async function (
}
expect(thrown, 'Batch should have failed').to.be.true;
};

// Checks that the server takes into account all transactions from the batch when calculating
// the fee.
Tester.prototype.testInvalidFeeBatch = async function (
sender: Wallet,
receiver: Wallet,
token: types.TokenLike,
amount: BigNumber
) {
// Ignore the second transfer.
const fee = await this.syncProvider.getTransactionsBatchFee(['Transfer'], [receiver.address()], token);

const tx_with_fee = {
to: receiver.address(),
token,
amount,
fee
};
const tx_without_fee = {
to: receiver.address(),
token,
amount,
fee: 0
};

let thrown = true;
try {
const handles = await sender.syncMultiTransfer([tx_without_fee, tx_with_fee]);
for (const handle of handles) {
await handle.awaitVerifyReceipt();
}
thrown = false; // this line should be unreachable
} catch (e) {
expect(e.jrpcError.message).to.equal('Transactions batch summary fee is too low');
}
expect(thrown, 'Batch should have failed').to.be.true;
};

0 comments on commit caee29d

Please sign in to comment.