Skip to content

Commit

Permalink
Minor adjustments
Browse files Browse the repository at this point in the history
Better failure report for deposit

A bit of print debugging wouldn't harm, would it?

Fix ordering of account updates in storage

Remove print debugging

Revert update_order_id change as it's not needed
  • Loading branch information
popzxc committed Oct 19, 2020
1 parent 18f55c7 commit b2a694c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 22 deletions.
24 changes: 12 additions & 12 deletions core/lib/storage/src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,32 @@ impl Into<(u32, AccountUpdate)> for StorageAccountDiff {
}

impl StorageAccountDiff {
/// Compares updates by `block number` then by `update_order_id` (which is number within block).
pub fn cmp_order(&self, other: &Self) -> Ordering {
self.block_number()
.cmp(&other.block_number())
.then(self.update_order_id().cmp(&other.update_order_id()))
}

/// Returns the index of the operation within block.
pub fn update_order_id(&self) -> i32 {
*match self {
match self {
StorageAccountDiff::BalanceUpdate(StorageAccountUpdate {
update_order_id, ..
}) => update_order_id,
}) => *update_order_id,
StorageAccountDiff::Create(StorageAccountCreation {
update_order_id, ..
}) => update_order_id,
}) => *update_order_id,
StorageAccountDiff::Delete(StorageAccountCreation {
update_order_id, ..
}) => update_order_id,
}) => *update_order_id,
StorageAccountDiff::ChangePubKey(StorageAccountPubkeyUpdate {
update_order_id,
..
}) => update_order_id,
}) => *update_order_id,
}
}

/// Compares updates by `block number` then by `update_order_id` (which is number within block).
pub fn cmp_order(&self, other: &Self) -> Ordering {
self.block_number()
.cmp(&other.block_number())
.then(self.update_order_id().cmp(&other.update_order_id()))
}

/// Returns the block index to which the operation belongs.
pub fn block_number(&self) -> i64 {
*match self {
Expand Down
8 changes: 4 additions & 4 deletions core/tests/ts-tests/tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import './misc';

const TX_AMOUNT = utils.parseEther('10.0');
// should be enough for ~100 test transactions (excluding fees), increase if needed
const DEPOSIT_AMOUNT = TX_AMOUNT.mul(100);
const DEPOSIT_AMOUNT = TX_AMOUNT.mul(200);

// prettier-ignore
const TestSuite = (token: types.TokenSymbol, transport: 'HTTP' | 'WS') =>
Expand All @@ -23,7 +23,7 @@ describe(`ZkSync integration tests (token: ${token}, transport: ${transport})`,

before('create tester and test wallets', async () => {
tester = await Tester.init('localhost', transport);
alice = await tester.fundedWallet('1.0');
alice = await tester.fundedWallet('5.0');
bob = await tester.emptyWallet();
operatorBalance = await tester.operatorBalance(token);
});
Expand Down Expand Up @@ -94,7 +94,7 @@ describe(`ZkSync integration tests (token: ${token}, transport: ${transport})`,
});

it('should succeed resending a previously failed tx', async () => {
let nick = await tester.fundedWallet('1.0');
let nick = await tester.fundedWallet('5.0');
let mike = await tester.emptyWallet();
await tester.testTransactionResending(nick, mike, token, TX_AMOUNT);
})
Expand All @@ -103,7 +103,7 @@ describe(`ZkSync integration tests (token: ${token}, transport: ${transport})`,
let carl: Wallet;

before('create a test wallet', async () => {
carl = await tester.fundedWallet('1.0');
carl = await tester.fundedWallet('5.0');
});

step('should execute full-exit on random wallet', async () => {
Expand Down
12 changes: 9 additions & 3 deletions core/tests/ts-tests/tests/priority-ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Tester } from './tester';
import { expect } from 'chai';
import { Wallet, types } from 'zksync';
import { BigNumber } from 'ethers';
import { sleep } from 'zksync/build/utils';

type TokenLike = types.TokenLike;

Expand All @@ -22,15 +23,20 @@ Tester.prototype.testDeposit = async function (wallet: Wallet, token: TokenLike,
approveDepositAmountForERC20: approve
});

await depositHandle.awaitReceipt();
const receipt = await depositHandle.awaitReceipt();
expect(receipt.executed, 'Deposit was not executed').to.be.true;
const balanceAfter = await wallet.getBalance(token);
expect(balanceAfter.sub(balanceBefore).eq(amount), 'Deposit failed').to.be.true;
expect(
balanceAfter.sub(balanceBefore).eq(amount),
`Deposit balance mismatch. Expected ${amount}, actual ${balanceAfter.sub(balanceBefore)}`
).to.be.true;
};

Tester.prototype.testFullExit = async function (wallet: Wallet, token: TokenLike, accountId?: number) {
const balanceBefore = await wallet.getBalance(token);
const handle = await wallet.emergencyWithdraw({ token, accountId });
await handle.awaitReceipt();
let receipt = await handle.awaitReceipt();
expect(receipt.executed, 'Full Exit was not executed').to.be.true;
const balanceAfter = await wallet.getBalance(token);
return [balanceBefore, balanceAfter];
};
5 changes: 3 additions & 2 deletions core/tests/ts-tests/tests/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ Tester.prototype.testTransfer = async function (
if (sender.address() === receiver.address()) {
expect(senderBefore.sub(fee).eq(senderAfter), 'Transfer to self failed').to.be.true;
} else {
expect(senderBefore.sub(senderAfter).eq(amount.add(fee)), 'Transfer failed').to.be.true;
expect(receiverAfter.sub(receiverBefore).eq(amount), 'Transfer failed').to.be.true;
expect(senderBefore.sub(senderAfter).eq(amount.add(fee)), 'Transfer failed (incorrect sender balance)').to.be
.true;
expect(receiverAfter.sub(receiverBefore).eq(amount), 'Transfer failed (incorrect receiver balance)').to.be.true;
}

this.runningFee = this.runningFee.add(fee);
Expand Down
1 change: 1 addition & 0 deletions sdk/zksync.js/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class Provider {
async notifyPriorityOp(serialId: number, action: "COMMIT" | "VERIFY"): Promise<PriorityOperationReceipt> {
if (this.transport.subscriptionsSupported()) {
return await new Promise((resolve) => {
const startTime = new Date().getTime();
const subscribe = this.transport.subscribe(
"ethop_subscribe",
[serialId, action],
Expand Down
2 changes: 1 addition & 1 deletion sdk/zksync.js/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export class Wallet {

if (changePubKey.fee == null) {
changePubKey.fee = 0;

const feeType = {
ChangePubKey: {
onchainPubkeyAuth: changePubKey.onchainAuth,
Expand Down

0 comments on commit b2a694c

Please sign in to comment.