Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nonce from pending and fixing nonce order #589

Merged
merged 10 commits into from
Apr 6, 2022
Merged

Nonce from pending and fixing nonce order #589

merged 10 commits into from
Apr 6, 2022

Conversation

ChaitanyaKonda
Copy link
Contributor

@ChaitanyaKonda ChaitanyaKonda commented Mar 21, 2022

Fixes #565

This PR

  • Ensures the nonce is taken including pending transactions in mempool too
  • Ensures that the L2 blocks within an array of L2 blocks receive nonce in order
  • Ensures that an array of L2 blocks receive nonce in order

This can be tested by adding the test file below into test/e2e/tokens, skipping other tests in this folder by adding .hold to its files name and running npm run test-e2e-tokens. Start a proposer after seeing the message Transfers submitted. Start Proposer. This should create an array of transfer transaction L2 blocks and submit at once. If the test is successful, then L2 blocks have been submitted in the right nonce order by the proposer.

Test file to

/* eslint-disable no-await-in-loop */
import chai from 'chai';
import chaiHttp from 'chai-http';
import chaiAsPromised from 'chai-as-promised';
import config from 'config';
import Nf3 from '../../../cli/lib/nf3.mjs';
import { expectTransaction, Web3Client } from '../../utils.mjs';
import logger from '../../../common-files/utils/logger.mjs';

// so we can use require with mjs file
chai.use(chaiHttp);
chai.use(chaiAsPromised);
const { expect } = chai;

const environment = config.ENVIRONMENTS[process.env.ENVIRONMENT] || config.ENVIRONMENTS.localhost;

const {
  fee,
  transferValue,
  txPerBlock,
  tokenConfigs: { tokenType, tokenId },
  mnemonics,
  signingKeys,
} = config.TEST_OPTIONS;

const nf3Users = [new Nf3(signingKeys.user1, environment), new Nf3(signingKeys.user2, environment)];
const web3Client = new Web3Client();

let erc20Address;
let stateAddress;
let eventLogs = [];

describe('ERC20 tests', () => {
  before(async () => {
    await nf3Users[0].init(mnemonics.user1);
    erc20Address = await nf3Users[0].getContractAddress('ERC20Mock');
    stateAddress = await nf3Users[0].stateContractAddress;
    web3Client.subscribeTo('logs', eventLogs, { address: stateAddress });
  });

  describe('Deposits', () => {
    it('should deposit some ERC20 crypto into a ZKP commitment', async function () {
      logger.debug(`      Sending ${txPerBlock} deposits...`);
      // We create enough transactions to fill blocks full of deposits.
      for (let i = 0; i < txPerBlock * 10; i++) {
        const res = await nf3Users[0].deposit(erc20Address, tokenType, transferValue, tokenId, fee);
        expectTransaction(res);
        logger.debug(`     Gas used was ${Number(res.gasUsed)}`);
        if (i === 2) {
          logger.info('Start Proposer');
          await new Promise(resolve => setTimeout(() => resolve(), 5000));
        }
      }
      eventLogs = await web3Client.waitForEvent(eventLogs, ['blockProposed'], 10);
      const balance = (await nf3Users[0].getLayer2Balances())[erc20Address][0].balance;
      expect(balance).to.be.equal(transferValue * txPerBlock * 10);
    });
  });

  after(async () => {
    await nf3Users[0].close();
    await web3Client.closeWeb3();
  });
});

@ChaitanyaKonda ChaitanyaKonda changed the title Chait/nonce Nonce from pending and fixing nonce order Mar 21, 2022
@ChaitanyaKonda ChaitanyaKonda temporarily deployed to AWS March 21, 2022 15:55 Inactive
@ChaitanyaKonda ChaitanyaKonda added DNM Do not merge and removed Merge conflict labels Mar 21, 2022
cli/lib/nf3.mjs Outdated Show resolved Hide resolved
Copy link
Contributor

@signorecello signorecello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm but there's a possible duplicate log

@ChaitanyaKonda ChaitanyaKonda temporarily deployed to AWS March 28, 2022 02:53 Inactive
@ChaitanyaKonda ChaitanyaKonda temporarily deployed to AWS March 28, 2022 02:54 Inactive
@ChaitanyaKonda ChaitanyaKonda temporarily deployed to AWS April 4, 2022 03:13 Inactive
@ChaitanyaKonda ChaitanyaKonda temporarily deployed to AWS April 4, 2022 12:37 Inactive
@ChaitanyaKonda ChaitanyaKonda removed the DNM Do not merge label Apr 5, 2022
@Westlad Westlad merged commit ffe718e into master Apr 6, 2022
@Westlad Westlad deleted the chait/nonce branch April 6, 2022 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants