Skip to content

Commit

Permalink
adding ci tests back (#87)
Browse files Browse the repository at this point in the history
* adding tests except libs-sol which require ganache running

* fix all eslint error in environment

* remove fungible token test

* names

* add nearbridge tests

* add codechecks

* add wasm target and coverage token

* wait ganache

* remove travis

* non interactive oz

* add code checks.yml

* disable codechecks
  • Loading branch information
ailisp authored Jun 15, 2020
1 parent c961178 commit 810267b
Show file tree
Hide file tree
Showing 22 changed files with 109 additions and 128 deletions.
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

3 changes: 3 additions & 0 deletions codechecks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# TODO: this repo not detected by codechecks, asked codechecks team
checks:
- name: eth-gas-reporter/codechecks
8 changes: 4 additions & 4 deletions environment/commands/eth-dump.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ETHDump {
const extractor = new EthProofExtractor();
extractor.initialize(ethNodeUrl);

if (kindOfData != 'headers' && kindOfData != 'proofs') {
if (kindOfData !== 'headers' && kindOfData !== 'proofs') {
console.log('Usage: node index.js dump headers\n node index.js dump proofs');
process.exit(2);
}
Expand All @@ -34,9 +34,9 @@ class ETHDump {
console.log(`Downloading block ${endBlock} down to ${startBlock} to ${path}. ${endBlock - startBlock + 1} blocks in total.`);

for (let b = endBlock; b >= startBlock; b--) {
if (kindOfData == 'headers') {
if (kindOfData === 'headers') {
await ETHDump.dumpHeaders(web3, b, path);
} else if (kindOfData == 'proofs') {
} else if (kindOfData === 'proofs') {
await ETHDump.dumpProofs(web3, extractor, b, path);
}
}
Expand All @@ -63,7 +63,7 @@ class ETHDump {
const block = await web3.eth.getBlock(b);
for (const txHash of block.transactions) {
const receipt = await extractor.extractReceipt(txHash);
if (receipt.logs.length == 0) {
if (receipt.logs.length === 0) {
continue;
}
const block = await extractor.extractBlock(receipt.blockNumber);
Expand Down
1 change: 0 additions & 1 deletion environment/commands/init-eth-erc20.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Web3 = require('web3');
const fs = require('fs');
const path = require('path');
const { RainbowConfig } = require('../lib/config');

class InitETHERC20 {
Expand Down
1 change: 0 additions & 1 deletion environment/commands/init-eth-locker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Web3 = require('web3');
const fs = require('fs');
const path = require('path');
const { RainbowConfig } = require('../lib/config');

class InitETHLocker {
Expand Down
2 changes: 1 addition & 1 deletion environment/commands/init-near-fun-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class InitNEARFunToken {
const tokenAccount = RainbowConfig.getParam('near-fun-token-account');
let tokenSk = RainbowConfig.maybeGetParam('near-fun-token-sk');
if (!tokenSk) {
console.log(`Secret key for fungible token is not specified. Reusing master secret key.`);
console.log('Secret key for fungible token is not specified. Reusing master secret key.');
tokenSk = masterSk;
RainbowConfig.setParam('near-fun-token-sk', tokenSk);
}
Expand Down
2 changes: 1 addition & 1 deletion environment/commands/stop/near.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class StopLocalNearNodeCommand {
console.log('Stopping local near node...');
const command = '~/.rainbowup/nearup/nearup stop';
try {
execSync(command);
execSync(command);
} catch (err) {
console.log('Error stopping local near node', err);
}
Expand Down
12 changes: 8 additions & 4 deletions environment/commands/stop/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ class StopManagedProcessCommand {
const serviceName = command._name;
console.log('Stopping process:', serviceName);
ProcessManager.stop(serviceName, (err) => {
if (err) {
if (err) {
console.log('Error stopping the process due to:', err);
process.exit(1);
}
console.log(serviceName, 'successfully stopped...');
ProcessManager.disconnect((err) => {});
}
console.log(serviceName, 'successfully stopped...');
ProcessManager.disconnect((err) => {
if (err) {
console.error(err);
}
});
});
}
}
Expand Down
11 changes: 5 additions & 6 deletions environment/commands/transfer-eth-erc20-to-near.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const {
Eth2NearClientContract,
} = require('../lib/eth2near-client-contract');


function sleep (ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
Expand Down Expand Up @@ -43,7 +42,7 @@ class TransferETHERC20ToNear {
try {
console.log('Approving token transfer.');
await ethERC20Contract.methods.approve(RainbowConfig.getParam('eth-locker-address'),
Number(amount)).send({
Number(amount)).send({
from: ethSenderAccount,
gas: 5000000,
handleRevert: true,
Expand All @@ -64,7 +63,7 @@ class TransferETHERC20ToNear {
try {
console.log('Transferring tokens from the ERC20 account to the token locker account.');
const transaction = await ethTokenLockerContract.methods.lockToken(RainbowConfig.getParam('eth-erc20-address'), Number(amount),
nearReceiverAccount)
nearReceiverAccount)
.send({
from: ethSenderAccount,
gas: 5000000,
Expand Down Expand Up @@ -113,10 +112,10 @@ class TransferETHERC20ToNear {
const clientAccount = RainbowConfig.getParam('eth2near-client-account');
const ethClientContract = new Eth2NearClientContract(nearMasterAccount, clientAccount);
while (true) {
let last_block_number = (await ethClientContract.last_block_number()).toNumber();
const last_block_number = (await ethClientContract.last_block_number()).toNumber();
if (last_block_number < blockNumber) {
let delay = 10;
console.log(`Eth2NearClient is currently at block ${last_block_number}. Waiting for block ${blockNumber}. Sleeping for ${delay} sec.`)
const delay = 10;
console.log(`Eth2NearClient is currently at block ${last_block_number}. Waiting for block ${blockNumber}. Sleeping for ${delay} sec.`);
await sleep(delay * 1000);
} else {
break;
Expand Down
55 changes: 26 additions & 29 deletions environment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,29 @@ RainbowConfig.declareOption(
);
RainbowConfig.declareOption(
'eth-locker-address',
'ETH address of the locker contract.'
'ETH address of the locker contract.',
);
RainbowConfig.declareOption(
'eth-locker-abi-path',
'Path to the .abi file definining Ethereum locker contract. This contract works in pair with mintable fungible token on NEAR blockchain.'
'Path to the .abi file definining Ethereum locker contract. This contract works in pair with mintable fungible token on NEAR blockchain.',
);
RainbowConfig.declareOption(
'eth-locker-bin-path',
'Path to the .bin file definining Ethereum locker contract. This contract works in pair with mintable fungible token on NEAR blockchain.'
'Path to the .bin file definining Ethereum locker contract. This contract works in pair with mintable fungible token on NEAR blockchain.',
);
RainbowConfig.declareOption(
'eth-erc20-address',
'ETH address of the ERC20 contract.'
'ETH address of the ERC20 contract.',
);
RainbowConfig.declareOption(
'eth-erc20-abi-path',
'Path to the .abi file definining Ethereum ERC20 contract.'
'Path to the .abi file definining Ethereum ERC20 contract.',
);
RainbowConfig.declareOption(
'eth-erc20-bin-path',
'Path to the .bin file definining Ethereum ERC20 contract.'
'Path to the .bin file definining Ethereum ERC20 contract.',
);



program.version('0.1.0');

// General-purpose commands.
Expand Down Expand Up @@ -184,7 +182,6 @@ stopCommand.command('ganache')
stopCommand.command('eth-relay')
.action(StopManagedProcessCommand.execute);


RainbowConfig.addOptions(
program.command('init-near-contracts')
.description('Deploys and initializes Eth2NearClient and Eth2NearProver contracts to NEAR blockchain.')
Expand Down Expand Up @@ -212,44 +209,44 @@ RainbowConfig.addOptions(
program.command('init-near-fun-token')
.description('Deploys and initializes mintable fungible token to NEAR blockchain. Requires locker on Ethereum side.')
.action(InitNEARFunToken.execute),
[
'near-fun-token-account',
'near-fun-token-sk',
'near-fun-token-contract-path',
'near-fun-token-init-balance',
]
[
'near-fun-token-account',
'near-fun-token-sk',
'near-fun-token-contract-path',
'near-fun-token-init-balance',
],
);

RainbowConfig.addOptions(
program.command('init-eth-locker')
.description('Deploys and initializes locker contract on Ethereum blockchain. Requires mintable fungible token on Near side.')
.action(InitETHLocker.execute),
.description('Deploys and initializes locker contract on Ethereum blockchain. Requires mintable fungible token on Near side.')
.action(InitETHLocker.execute),
[
'eth-node-url',
'eth-master-sk',
'eth-locker-abi-path',
'eth-locker-bin-path'
]
'eth-locker-bin-path',
],
);

RainbowConfig.addOptions(
program.command('init-eth-erc20')
.description('Deploys and initializes ERC20 contract on Ethereum blockchain.')
.action(InitETHERC20.execute),
.description('Deploys and initializes ERC20 contract on Ethereum blockchain.')
.action(InitETHERC20.execute),
[
'eth-node-url',
'eth-master-sk',
'eth-erc20-abi-path',
'eth-erc20-bin-path'
]
'eth-erc20-bin-path',
],
);

RainbowConfig.addOptions(
program.command('transfer-eth-erc20-to-near')
.action(TransferETHERC20ToNear.execute)
.option('--amount <amount>', 'Amount of ERC20 tokens to transfer')
.option('--eth-sender-sk <eth_sender_sk>', 'The secret key of the Ethereum account that will be sending ERC20 token.')
.option('--near-receiver-account <near_receiver_account>', 'The account on NEAR blockchain that will be receiving the minted token.'),
.action(TransferETHERC20ToNear.execute)
.option('--amount <amount>', 'Amount of ERC20 tokens to transfer')
.option('--eth-sender-sk <eth_sender_sk>', 'The secret key of the Ethereum account that will be sending ERC20 token.')
.option('--near-receiver-account <near_receiver_account>', 'The account on NEAR blockchain that will be receiving the minted token.'),
[
'eth-node-url',
'eth-erc20-address',
Expand All @@ -261,8 +258,8 @@ RainbowConfig.addOptions(
'near-fun-token-account',
'eth2near-client-account',
'near-master-account',
'near-master-sk'
]
'near-master-sk',
],
);

program.command('eth-dump <kind_of_data>')
Expand Down
19 changes: 12 additions & 7 deletions environment/lib/borsh/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ const Web3 = require('web3');
const nearlib = require('nearlib');

const BN = require('bn.js');
const { TextDecoder } = require('util');

class BorshError extends Error {
constructor (message) {
super(message);

this.name = this.constructor.name;
}
}

function serializeField (schema, value, fieldType, writer) {
if (fieldType === 'u8') {
Expand Down Expand Up @@ -145,8 +154,9 @@ class BinaryReader {
read_string () {
const len = this.read_u32();
const buf = this.read_buffer(len);
const textDecoder = TextDecoder();
try {
// NOTE: Using TextDecoder to fail on invalid UTF-8
// NOTE: Using TextDecoder to fail on invalid UTF-8
return textDecoder.decode(buf);
} catch (e) {
throw new BorshError(`Error decoding UTF-8 string: ${e}`);
Expand Down Expand Up @@ -190,12 +200,7 @@ const signAndSendTransaction = async (accessKey, account, receiverId, actions) =
);
console.log('TxHash', nearlib.utils.serialize.base_encode(txHash));

let result;
try {
result = await account.connection.provider.sendTransaction(signedTx);
} catch (error) {
throw error;
}
const result = await account.connection.provider.sendTransaction(signedTx);

const flatLogs = [result.transaction_outcome, ...result.receipts_outcome].reduce((acc, it) => acc.concat(it.outcome.logs), []);
if (flatLogs) {
Expand Down
12 changes: 6 additions & 6 deletions environment/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ class RainbowConfig {
if (this.configFile.has(camelCase)) {
return this.configFile.get(camelCase);
} else {
const decl = this.paramDeclarations[name];
if (decl.defaultValue) {
return decl.defaultValue;
} else {
return null;
}
const decl = this.paramDeclarations[name];
if (decl.defaultValue) {
return decl.defaultValue;
} else {
return null;
}
}
} else {
return this.paramValues[name].value;
Expand Down
2 changes: 1 addition & 1 deletion environment/lib/eth-proof-extractor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class EthProofExtractor {
}

async extractProof (block, tree, transactionIndex) {
const [_, __, stack] = await promisfy(tree.findPath, tree)(encode(transactionIndex));
const [, , stack] = await promisfy(tree.findPath, tree)(encode(transactionIndex));
return {
header: Header.fromRpc(block),
receiptProof: Proof.fromStack(stack),
Expand Down
14 changes: 7 additions & 7 deletions environment/lib/eth-prover-tester/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const {
receiptFromWeb3,
logFromWeb3,
} = require('../eth-proof-extractor');
const {
borshSchema,
} = require('../eth-prover-contract');
const {
serialize,
} = require('../borsh');
// const {
// borshSchema,
// } = require('../eth-prover-contract');
// const {
// serialize,
// } = require('../borsh');

// Tests EthProver in the following way:
// * Gets the last block submitted to EthClient;
Expand Down Expand Up @@ -48,7 +48,7 @@ class EthProverTester {
const block = await this.web3.eth.getBlock(currBlock);
for (const txHash of block.transactions) {
const receipt = await extractor.extractReceipt(txHash);
if (receipt.logs.length == 0) {
if (receipt.logs.length === 0) {
continue;
}
const block = await extractor.extractBlock(receipt.blockNumber);
Expand Down
Loading

0 comments on commit 810267b

Please sign in to comment.