Skip to content

Commit

Permalink
fix: making changes as suggested in the PR
Browse files Browse the repository at this point in the history
  • Loading branch information
signorecello committed Feb 17, 2022
1 parent 6ca1b30 commit 0afa0f6
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 135 deletions.
4 changes: 1 addition & 3 deletions cli/lib/nf3.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,10 @@ class Nf3 {
contractAddress = this.shieldContractAddress,
fee = this.defaultFee,
) {
// We'll manage the nonce ourselves because we can run too fast for the blockchain client to update
// we need a Mutex so that we don't get a nonce-updating race.

let tx;
await this.nonceMutex.runExclusive(async () => {
// if we don't have a nonce, we must get one from the ethereum client
this.nonce = await this.web3.eth.getTransactionCount(this.ethereumAddress);

let gasPrice = 20000000000;
Expand Down Expand Up @@ -438,7 +436,7 @@ class Nf3 {
});
this.latestWithdrawHash = res.data.transaction.transactionHash;
if (!offchain) {
const receiptPromise = await this.submitTransaction(
const receiptPromise = this.submitTransaction(
res.data.txDataToSign,
this.shieldContractAddress,
fee,
Expand Down
52 changes: 24 additions & 28 deletions config/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,13 @@ module.exports = {
},
},
TEST_OPTIONS: {
tokenId: '0x00',
tokenType: 'ERC20', // it can be 'ERC721' or 'ERC1155'
tokenTypeERC721: 'ERC721',
tokenTypeERC1155: 'ERC1155',
value: 10,
tokenConfigs: {
tokenId: '0x00',
tokenType: 'ERC20', // it can be 'ERC721' or 'ERC1155'
tokenTypeERC721: 'ERC721',
tokenTypeERC1155: 'ERC1155',
},
transferValue: 10,
// this is the etherum private key for accounts[0]
privateKey: '0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69e',
gas: 10000000,
Expand All @@ -176,28 +178,22 @@ module.exports = {
BLOCK_STAKE: 1, // 1 wei
bond: 10, // 10 wei
txPerBlock: 2,
walletTestAddress: '0xfCb059A4dB5B961d3e48706fAC91a55Bad0035C9',
walletTestSigningkey: '0xd42905d0582c476c4b74757be6576ec323d715a0c7dcff231b6348b7ab0190eb',
ethereumSigningKeyUser1: '0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69e',
ethereumAddressUser1: '0x9c8b2276d490141ae1440da660e470e7c0349c63',
ethereumSigningKeyUser2: '0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69e',
ethereumSigningKeyProposer1:
'0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69d',
ethereumSigningKeyProposer2:
'0xd42905d0582c476c4b74757be6576ec323d715a0c7dcff231b6348b7ab0190eb',
ethereumSigningKeyProposer3:
'0xfbc1ee1c7332e2e5a76a99956f50b3ba2639aff73d56477e877ef8390c41e0c6',
ethereumSigningKeyChallenger:
'0xd42905d0582c476c4b74757be6576ec323d715a0c7dcff231b6348b7ab0190eb',
ethereumSigningKeyLiquidityProvider:
'0xfbc1ee1c7332e2e5a76a99956f50b3ba2639aff73d56477e877ef8390c41e0c6',
mnemonicUser1: 'trip differ bamboo bundle bonus luxury strike mad merry muffin nose auction',
mnemonicUser2:
'control series album tribe category saddle prosper enforce moon eternal talk fame',
mnemonicProposer: 'high return hold whale promote payment hat panel reduce oyster ramp mouse',
mnemonicChallenger:
'crush power outer gadget enter maze advance rather divert monster indoor axis',
mnemonicLiquidityProvider:
'smart base soup sister army address member poem point quick save penalty',
signingKeys: {
walletTest: '0xd42905d0582c476c4b74757be6576ec323d715a0c7dcff231b6348b7ab0190eb',
user1: '0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69e',
user2: '0xd42905d0582c476c4b74757be6576ec323d715a0c7dcff231b6348b7ab0190eb',
proposer1: '0x4775af73d6dc84a0ae76f8726bda4b9ecf187c377229cb39e1afa7a18236a69d',
proposer2: '0xd42905d0582c476c4b74757be6576ec323d715a0c7dcff231b6348b7ab0190eb',
proposer3: '0xfbc1ee1c7332e2e5a76a99956f50b3ba2639aff73d56477e877ef8390c41e0c6',
challenger: '0xd42905d0582c476c4b74757be6576ec323d715a0c7dcff231b6348b7ab0190eb',
liquidityProvider: '0xfbc1ee1c7332e2e5a76a99956f50b3ba2639aff73d56477e877ef8390c41e0c6',
},
mnemonics: {
user1: 'trip differ bamboo bundle bonus luxury strike mad merry muffin nose auction',
user2: 'control series album tribe category saddle prosper enforce moon eternal talk fame',
proposer: 'high return hold whale promote payment hat panel reduce oyster ramp mouse',
challenger: 'crush power outer gadget enter maze advance rather divert monster indoor axis',
liquidityProvider: 'smart base soup sister army address member poem point quick save penalty',
},
},
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"neg-test-ropsten": "mocha --timeout 0 --bail --exit test/neg-http.mjs",
"test-e2e-protocol": "mocha --timeout 0 --bail --parallel --exit test/e2e/protocol/*.test.mjs ",
"test-gas": "mocha --timeout 0 --bail --exit test/e2e/gas.test.mjs ",
"test-e2e-tokens": "mocha --timeout 0 --bail --parallel --exit test/e2e/tokens/*.test.mjs ",
"test-e2e-tokens": "mocha --timeout 0 --bail --exit test/e2e/tokens/*.test.mjs ",
"lint": "eslint . --ext js,mjs,jsx && find-unused-exports",
"prepare": "husky install",
"doc:build:sdk": "jsdoc -c jsdoc.json cli/lib/nf3.mjs"
Expand Down
7 changes: 0 additions & 7 deletions test/e2e/configs.json

This file was deleted.

30 changes: 0 additions & 30 deletions test/e2e/environments.json

This file was deleted.

7 changes: 0 additions & 7 deletions test/e2e/mnemonics.json

This file was deleted.

7 changes: 2 additions & 5 deletions test/e2e/protocol/challenger.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ import chai from 'chai';
import config from 'config';
import chaiHttp from 'chai-http';
import chaiAsPromised from 'chai-as-promised';
import { createRequire } from 'module';
import Nf3 from '../../../cli/lib/nf3.mjs';

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

// we need require here to import jsons
const environment = config.ENVIRONMENTS[process.env.ENVIRONMENT] || config.ENVIRONMENTS.localhost;
const signingKeys = require('../signingKeys.json');
const mnemonics = require('../mnemonics.json');

const { mnemonics, signingKeys } = config.TEST_OPTIONS;

const nf3Challenger = new Nf3(signingKeys.challenger, environment);

Expand Down
6 changes: 1 addition & 5 deletions test/e2e/protocol/health-and-contracts.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@ import chai from 'chai';
import config from 'config';
import chaiHttp from 'chai-http';
import chaiAsPromised from 'chai-as-promised';
import { createRequire } from 'module';
import Nf3 from '../../../cli/lib/nf3.mjs';

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

// we need require here to import jsons
const environment = config.ENVIRONMENTS[process.env.ENVIRONMENT] || config.ENVIRONMENTS.localhost;
const mnemonics = require('../mnemonics.json');
const signingKeys = require('../signingKeys.json');
const { mnemonics, signingKeys } = config.TEST_OPTIONS;

const nf3User1 = new Nf3(signingKeys.user1, environment);

Expand Down
7 changes: 1 addition & 6 deletions test/e2e/protocol/proposer.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,17 @@ import chai from 'chai';
import chaiHttp from 'chai-http';
import chaiAsPromised from 'chai-as-promised';
import config from 'config';
import { createRequire } from 'module';
import Nf3 from '../../../cli/lib/nf3.mjs';
import { Web3Client, expectTransaction } from '../../utils.mjs';

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

// we need require here to import jsons
const environment = config.ENVIRONMENTS[process.env.ENVIRONMENT] || config.ENVIRONMENTS.localhost;

const mnemonics = require('../mnemonics.json');
const signingKeys = require('../signingKeys.json');
const { bond, gasCosts, txPerBlock } = require('../configs.json');
const { bond, gasCosts, txPerBlock, mnemonics, signingKeys } = config.TEST_OPTIONS;

const testProposers = [
new Nf3(signingKeys.proposer1, environment),
Expand Down
10 changes: 0 additions & 10 deletions test/e2e/signingKeys.json

This file was deleted.

6 changes: 0 additions & 6 deletions test/e2e/tokenConfigs.json

This file was deleted.

16 changes: 8 additions & 8 deletions test/e2e/tokens/erc1155.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ import chai from 'chai';
import chaiHttp from 'chai-http';
import chaiAsPromised from 'chai-as-promised';
import config from 'config';
import { createRequire } from 'module';
import Nf3 from '../../../cli/lib/nf3.mjs';
import { expectTransaction, Web3Client, depositNTransactions } from '../../utils.mjs';
import { getERCInfo } from '../../../cli/lib/tokens.mjs';

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

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

// we need require here to import jsons
const mnemonics = require('../mnemonics.json');
const signingKeys = require('../signingKeys.json');
const { fee, txPerBlock, transferValue } = require('../configs.json');
const { tokenTypeERC1155 } = require('../tokenConfigs.json');
const { tokenType, tokenId } = require('../tokenConfigs.json');
const {
fee,
txPerBlock,
transferValue,
tokenConfigs: { tokenTypeERC1155, tokenType, tokenId },
mnemonics,
signingKeys,
} = config.TEST_OPTIONS;

const nf3Users = [new Nf3(signingKeys.user1, environment), new Nf3(signingKeys.user2, environment)];
const nf3Proposer1 = new Nf3(signingKeys.proposer1, environment);
Expand Down
15 changes: 8 additions & 7 deletions test/e2e/tokens/erc20.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@
import chai from 'chai';
import chaiHttp from 'chai-http';
import chaiAsPromised from 'chai-as-promised';
import { createRequire } from 'module';
import config from 'config';
import Nf3 from '../../../cli/lib/nf3.mjs';
import { expectTransaction, depositNTransactions, Web3Client } from '../../utils.mjs';

import { approve } from '../../../cli/lib/tokens.mjs';

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

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

// we need require here to import jsons
const mnemonics = require('../mnemonics.json');
const signingKeys = require('../signingKeys.json');
const { fee, transferValue, txPerBlock } = require('../configs.json');
const { tokenType, tokenId } = require('../tokenConfigs.json');
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 nf3Proposer = new Nf3(signingKeys.proposer1, environment);
Expand Down
16 changes: 8 additions & 8 deletions test/e2e/tokens/erc721.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import chai from 'chai';
import chaiHttp from 'chai-http';
import chaiAsPromised from 'chai-as-promised';
import config from 'config';
import { createRequire } from 'module';
import Nf3 from '../../../cli/lib/nf3.mjs';
import { expectTransaction, Web3Client, depositNTransactions } from '../../utils.mjs';
import { getERCInfo } from '../../../cli/lib/tokens.mjs';

// so we can use require with mjs file
const require = createRequire(import.meta.url);
const { expect } = chai;
chai.use(chaiHttp);
chai.use(chaiAsPromised);
const environment = config.ENVIRONMENTS[process.env.ENVIRONMENT] || config.ENVIRONMENTS.localhost;

// we need require here to import jsons
const mnemonics = require('../mnemonics.json');
const signingKeys = require('../signingKeys.json');
const { fee, txPerBlock, transferValue } = require('../configs.json');
const { tokenTypeERC721 } = require('../tokenConfigs.json');
const { tokenType, tokenId } = require('../tokenConfigs.json');
const {
fee,
txPerBlock,
transferValue,
tokenConfigs: { tokenTypeERC721, tokenType, tokenId },
mnemonics,
signingKeys,
} = config.TEST_OPTIONS;

const nf3Users = [new Nf3(signingKeys.user1, environment), new Nf3(signingKeys.user2, environment)];
const nf3Proposer1 = new Nf3(signingKeys.proposer1, environment);
Expand Down
17 changes: 13 additions & 4 deletions test/rollback-resync.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
Web3Client,
} from './utils.mjs';

const { privateKey, gas, BLOCK_STAKE, fee, tokenId, value, tokenType, bond } = config.TEST_OPTIONS;
const { privateKey, gas, BLOCK_STAKE, fee, tokenId, transferValue, tokenType, bond } =
config.TEST_OPTIONS;

const { spawn } = childProcess;
const { expect } = chai;
Expand Down Expand Up @@ -86,12 +87,20 @@ describe('Running rollback and resync test', () => {
.send({ mnemonic, path: `m/44'/60'/0'/0` })
).body);

defaultDepositArgs = { ercAddress, tokenId, tokenType, value, pkd: pkd1, nsk: nsk1, fee };
defaultDepositArgs = {
ercAddress,
tokenId,
tokenType,
transferValue,
pkd: pkd1,
nsk: nsk1,
fee,
};
defaultTransferArgs = {
ercAddress,
tokenId,
recipientData: {
values: [value],
transferValues: [transferValue],
recipientPkds: [pkd1],
},
nsk: nsk1,
Expand All @@ -118,7 +127,7 @@ describe('Running rollback and resync test', () => {
const msg = JSON.parse(message.data);
const { type, txDataToSign, block, transactions } = msg;
if (type === 'block') {
// third last input is msg.value
// third last input is msg.transferValue
// eslint-disable-next-line prettier/prettier
await blockSubmissionFunction(
txDataToSign,
Expand Down

0 comments on commit 0afa0f6

Please sign in to comment.