Skip to content

Commit

Permalink
Fix ci (#636)
Browse files Browse the repository at this point in the history
* Apply `prettier` and `standard`

* Rebuild contracts

* Change ganache url protocol from `ws` to `htttp`

* Fix import `Common` class

* Upgrade to ganache `7.0.0-alpha.1` to support hardfork london

* Fix deploying erc20 token

* Improve checking empty block object

* Update web3 package

* Update `rainbow-token-connector` package

* Fix `replacement transaction underpriced` error

* Apply linter fix

* Update `eth-object` package

* Fix factory sub account

* Fix `neartokenfactory` sub account

* Add logs

* Fix default value of 'near-token-factory-account' option

* Temporary workaround to fix `balanceOf` call

* Apply `standard` and increase pipelines timeout

* Remove commented-out code

Co-authored-by: Karim <[email protected]>
  • Loading branch information
karim-en and karim-en authored Nov 10, 2021
1 parent fd7019f commit 63fb73b
Show file tree
Hide file tree
Showing 31 changed files with 1,735 additions and 1,976 deletions.
8 changes: 4 additions & 4 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ steps:
artifact_paths:
- "logs/**/*.log"
timeout: 40
timeout: 60

agents:
- "queue=default"
Expand All @@ -32,7 +32,7 @@ steps:
artifact_paths:
- "logs/**/*.log"
timeout: 40
timeout: 60

agents:
- "queue=default"
Expand All @@ -45,7 +45,7 @@ steps:
artifact_paths:
- "logs/**/*.log"
timeout: 40
timeout: 60

agents:
- "queue=default"
Expand All @@ -58,7 +58,7 @@ steps:
artifact_paths:
- "logs/**/*.log"
timeout: 40
timeout: 60

agents:
- "queue=default"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ RUN apt-get update -qq && apt-get install -y \
&& rm -rf /var/lib/apt/lists/* \
&& curl -sL https://deb.nodesource.com/setup_12.x | bash -

RUN apt-get install nodejs && npm -g install ganache-cli yarn
RUN apt-get install nodejs && npm -g install ganache@7.0.0-alpha.1 yarn

RUN curl https://sh.rustup.rs -sSf | \
sh -s -- -y --no-modify-path --default-toolchain nightly-2020-05-15
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ Now you check the balance of `node0` again. You should notice the balance was ch

Note, when we deployed ERC20 to the Ethereum blockchain we have minted a large number of tokens to the default master
key of Ganache, so we have transferred ERC20 tokens from it to `node0` account.
Notice that we are using `neartokenfactory` account here to pay for the NEAR gas fees, any account for which we know a secret key would've worked too.
Notice that we are using `neartokenfactory.node0` account here to pay for the NEAR gas fees, any account for which we know a secret key would've worked too.
You must observe blocks being submitted.

You can also manually check the ERC20 balance of the receiver before and after receiving the transfer back from the NEAR side
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/start/eth2near-relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { nearAPI } = require('rainbow-bridge-utils')
const path = require('path')

class StartEth2NearRelayCommand {
static async execute({
static async execute ({
daemon,
nearNetworkId,
nearNodeUrl,
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/start/ganache.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class StartGanacheNodeCommand {
})
})
return {
ethNodeUrl: 'ws://localhost:9545',
ethNodeUrl: 'http://localhost:9545',
ethMasterSk: '0x2bdd21761a483f71054e14f5b827213567971c676928d9a1808cbfa4b7501200',
nearClientValidateEthash: 'false'
}
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/start/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function getLocalNearNodeURL (port = NEAR_PORT) {
}

function getLocalGanacheNodeURL (port = GANACHE_PORT) {
return util.format('ws://localhost:%d', port)
return util.format('http://localhost:%d', port)
}

exports.NEAR_PORT = NEAR_PORT
Expand Down
8 changes: 4 additions & 4 deletions cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ RainbowConfig.declareOption(
RainbowConfig.declareOption(
'near-token-factory-account',
'The account of the token factory contract that will be used to mint tokens locked on Ethereum.',
'neartokenfactory'
'neartokenfactory.node0'
)
RainbowConfig.declareOption(
'near-token-factory-sk',
Expand Down Expand Up @@ -909,6 +909,6 @@ RainbowConfig.addOptions(
['near-node-url']
)

; (async () => {
await program.parseAsync(process.argv)
})()
; (async () => {
await program.parseAsync(process.argv)
})()
86 changes: 49 additions & 37 deletions cli/init/eth-contracts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const BN = require('bn.js')
const fs = require('fs')
const { Web3, normalizeEthKey } = require('rainbow-bridge-utils')
const { Web3, normalizeEthKey, sleep } = require('rainbow-bridge-utils')

const RETRY_SEND_TX = 15

class EthContractInitializer {
async execute ({
Expand All @@ -18,45 +20,55 @@ class EthContractInitializer {
return null
}

try {
const web3 = new Web3(ethNodeUrl)
let ethMasterAccount = web3.eth.accounts.privateKeyToAccount(
normalizeEthKey(ethMasterSk)
)
web3.eth.accounts.wallet.add(ethMasterAccount)
web3.eth.defaultAccount = ethMasterAccount.address
ethMasterAccount = ethMasterAccount.address
for (let i = 0; i < RETRY_SEND_TX; i++) {
try {
const web3 = new Web3(ethNodeUrl)
let ethMasterAccount = web3.eth.accounts.privateKeyToAccount(
normalizeEthKey(ethMasterSk)
)
web3.eth.accounts.wallet.add(ethMasterAccount)
web3.eth.defaultAccount = ethMasterAccount.address
ethMasterAccount = ethMasterAccount.address

console.log('Deploying ETH contract')
let abi, bytecode
if (ethContractArtifactPath) {
({ abi, bytecode } = JSON.parse(fs.readFileSync(ethContractArtifactPath)))
} else {
abi = JSON.parse(fs.readFileSync(ethContractAbiPath))
bytecode = '0x' + fs.readFileSync(ethContractBinPath)
console.log('Deploying ETH contract')
let abi, bytecode
if (ethContractArtifactPath) {
({ abi, bytecode } = JSON.parse(fs.readFileSync(ethContractArtifactPath)))
} else {
abi = JSON.parse(fs.readFileSync(ethContractAbiPath))
bytecode = '0x' + fs.readFileSync(ethContractBinPath)
}
const tokenContract = new web3.eth.Contract(abi)
const txContract = await tokenContract
.deploy({
data: bytecode,
arguments: args
})
.send({
from: ethMasterAccount,
gas,
gasPrice: new BN(await web3.eth.getGasPrice()).mul(new BN(ethGasMultiplier))
})
ethContractAddress = normalizeEthKey(txContract.options.address)
console.log(`Deployed ETH contract to ${ethContractAddress}`)
try {
// Only WebSocket provider can close.
web3.currentProvider.connection.close()
} catch (e) {
}
return { ethContractAddress }
} catch (e) {
if (e.message.indexOf('the tx doesn\'t have the correct nonce') >= 0 ||
e.message.indexOf('replacement transaction underpriced') >= 0) {
console.log('nonce error, retrying...')
await sleep(5 * 1000)
continue
}

console.log(e)
return null
}
const tokenContract = new web3.eth.Contract(abi)
const txContract = await tokenContract
.deploy({
data: bytecode,
arguments: args
})
.send({
from: ethMasterAccount,
gas,
gasPrice: new BN(await web3.eth.getGasPrice()).mul(new BN(ethGasMultiplier))
})
ethContractAddress = normalizeEthKey(txContract.options.address)
console.log(`Deployed ETH contract to ${ethContractAddress}`)
try {
// Only WebSocket provider can close.
web3.currentProvider.connection.close()
} catch (e) {}
} catch (e) {
console.log(e)
return null
}
return { ethContractAddress }
}
}

Expand Down
2 changes: 1 addition & 1 deletion cli/init/near-contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
} = require('rainbow-bridge-eth2near-block-relay')

class InitNearContracts {
static async execute({
static async execute ({
nearMasterAccount,
nearMasterSk,
nearClientAccount,
Expand Down
4 changes: 2 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"bn.js": "^5.1.3",
"commander": "^5.1.0",
"eth-object": "near/eth-object#54e03b8aac8208cf724e206d49ffb8bdd30451d7",
"eth-object": "https://github.com/near/eth-object#383b6ea68c7050bea4cab6950c1d5a7fa553e72b",
"eth-util-lite": "near/eth-util-lite#master",
"ethereumjs-util": "^6.2.0",
"node-fetch": "^2.6.0",
Expand All @@ -34,7 +34,7 @@
"rainbow-bridge-near2eth-block-relay": "1.0.0",
"rainbow-bridge-watchdog": "1.0.0",
"rainbow-bridge-testing": "1.0.0",
"rainbow-token-connector": "near/rainbow-token-connector#7fb86958362fe8e4455ebbcdb00caac067eda2ff",
"rainbow-token-connector": "near/rainbow-token-connector#134b3b6ad900d90c6f993c52f4e3edf985aec61a",
"request": "^2.88.2"
}
}
Loading

0 comments on commit 63fb73b

Please sign in to comment.