Skip to content

Commit

Permalink
CI: fix E2E tests (#838)
Browse files Browse the repository at this point in the history
* Update `near-api-js` package to v1.1.0.
* Set `near2eth-relay-block-select-duration` to 0.
  • Loading branch information
karim-en authored Oct 13, 2022
1 parent cd2c9ef commit fcab67c
Show file tree
Hide file tree
Showing 20 changed files with 65 additions and 59 deletions.
4 changes: 1 addition & 3 deletions cli/commands/start/eth2near-relay.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ class StartEth2NearRelayCommand {
nodeUrl: nearNodeUrl,
networkId: nearNetworkId,
masterAccount: nearMasterAccount,
deps: {
keyStore: keyStore
}
keyStore
})

const relay = new Eth2NearRelay()
Expand Down
4 changes: 1 addition & 3 deletions cli/commands/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,7 @@ class NearStatus {
nodeUrl: nearNodeUrl,
nearNetworkId,
masterAccount: nearMasterAccount,
deps: {
keyStore: keyStore
}
keyStore
})
this.masterAccount = (await verifyAccountGently(near, nearMasterAccount))
? new Status(nearMasterAccount, Ok, Valid)
Expand Down
4 changes: 1 addition & 3 deletions cli/commands/update-dag-merkle-roots.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ class UpdateDagMerkleRoots {
const near = await nearAPI.connect({
nodeUrl: nearNodeUrl,
networkId: nearNetworkId,
deps: {
keyStore: keyStore
}
keyStore
})

console.log(`DAG Merkle roots SHA256-checksum: ${sha256(JSON.stringify(dagMerkleRoots, null, 2))}`)
Expand Down
4 changes: 1 addition & 3 deletions cli/init/near-contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ class InitNearContracts {
nodeUrl: nearNodeUrl,
networkId: nearNetworkId,
masterAccount: nearMasterAccount,
deps: {
keyStore: keyStore
}
keyStore
})

console.log('Creating accounts and deploying the contracts.')
Expand Down
2 changes: 1 addition & 1 deletion cli/init/near-token-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class InitNearTokenFactory {
nodeUrl: nearNodeUrl,
networkId: nearNetworkId,
masterAccount: nearMasterAccount,
deps: { keyStore: keyStore }
keyStore
})

await verifyAccount(near, nearMasterAccount)
Expand Down
2 changes: 1 addition & 1 deletion eth2near/eth2near-block-relay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class Eth2NearRelay {
actions.push(action)
}

const task = this.ethClientContract.account.signAndSendTransaction(this.ethClientContract.contractId, actions)
const task = this.ethClientContract.account.signAndSendTransaction({ receiverId: this.ethClientContract.contractId, actions })

console.log(
`Submit txn to add block ${clientBlockNumber + 1
Expand Down
4 changes: 1 addition & 3 deletions near2eth/near2eth-block-relay/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ class Near2EthRelay {
this.near = await nearAPI.connect({
nodeUrl: nearNodeUrl,
networkId: nearNetworkId,
deps: {
keyStore: keyStore
}
keyStore
})

// Declare Near2EthClient contract.
Expand Down
2 changes: 1 addition & 1 deletion testing/adapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ async function getBridgeOnNearBalance ({
nodeUrl: nearNodeUrl,
networkId: nearNetworkId,
masterAccount: nearReceiverAccount,
deps: { keyStore: keyStore }
keyStore
})

const nearAccount = new nearAPI.Account(
Expand Down
2 changes: 1 addition & 1 deletion testing/ci/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ node index.js init-near-token-factory
yarn run pm2 ping
sleep 5
yarn run pm2 list
node index.js start near2eth-relay --near2eth-relay-min-delay 1 --near2eth-relay-max-delay 30 --near2eth-relay-after-submit-delay-ms 40000 --near2eth-relay-block-select-duration 5
node index.js start near2eth-relay --near2eth-relay-min-delay 1 --near2eth-relay-max-delay 30 --near2eth-relay-after-submit-delay-ms 40000 --near2eth-relay-block-select-duration 0
sleep 5
yarn run pm2 list
node index.js start eth2near-relay
Expand Down
2 changes: 1 addition & 1 deletion testing/ci/test_ethrelay_catchup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ node index.js init-near-token-factory
yarn run pm2 ping
sleep 5
yarn run pm2 list
node index.js start near2eth-relay --near2eth-relay-min-delay 1 --near2eth-relay-max-delay 30 --near2eth-relay-after-submit-delay-ms 15000 --near2eth-relay-block-select-duration 5
node index.js start near2eth-relay --near2eth-relay-min-delay 1 --near2eth-relay-max-delay 30 --near2eth-relay-after-submit-delay-ms 15000 --near2eth-relay-block-select-duration 0
sleep 5
yarn run pm2 list
sleep 100
Expand Down
2 changes: 1 addition & 1 deletion testing/transfer-eth-erc20/deploy-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class DeployToken {
nodeUrl: nearNodeUrl,
networkId: nearNetworkId,
masterAccount: nearMasterAccount,
deps: { keyStore: keyStore }
keyStore
})

await verifyAccount(near, nearMasterAccount)
Expand Down
2 changes: 1 addition & 1 deletion testing/transfer-eth-erc20/from-near.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class TransferEthERC20FromNear {
nodeUrl: nearNodeUrl,
networkId: nearNetworkId,
masterAccount: nearSenderAccountId,
deps: { keyStore: keyStore }
keyStore
})
const nearSenderAccount = new nearAPI.Account(
near.connection,
Expand Down
2 changes: 1 addition & 1 deletion testing/transfer-eth-erc20/to-near.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class TransferETHERC20ToNear {
nodeUrl: nearNodeUrl,
networkId: nearNetworkId,
masterAccount: nearMasterAccountId,
deps: { keyStore: keyStore }
keyStore
})
const nearMasterAccount = new nearAPI.Account(
near.connection,
Expand Down
4 changes: 1 addition & 3 deletions utils/address-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ class AddressWatcher {
this.near = await nearAPI.connect({
nodeUrl: nearNodeUrl,
networkId: networkId,
deps: {
keyStore: new nearAPI.keyStores.InMemoryKeyStore()
}
keyStore: new nearAPI.keyStores.InMemoryKeyStore()
})

this.metricsPort = metricsPort
Expand Down
33 changes: 18 additions & 15 deletions utils/borsh.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ class BorshError extends Error {

function serializeField (schema, value, fieldType, writer) {
if (fieldType === 'u8') {
writer.write_u8(value)
writer.writeU8(value)
} else if (fieldType === 'u64') {
writer.write_u64(value)
writer.writeU64(value)
} else if (fieldType === 'u128') {
writer.write_u128(value)
writer.writeU128(value)
} else if (fieldType === 'bool') {
return writer.write_u8(value ? 1 : 0)
return writer.writeU8(value ? 1 : 0)
} else if (fieldType === 'string') {
return writer.write_string(value)
return writer.writeString(value)
} else if (fieldType instanceof Array) {
if (typeof fieldType[0] === 'number') {
if (value.length !== fieldType[0]) {
throw new Error(
`Expecting byte array of length ${fieldType[0]}, but got ${value.length} bytes`
)
}
writer.write_fixed_array(value)
writer.writeFixedArray(value)
} else {
writer.write_array(value, (item) => {
writer.writeArray(value, (item) => {
serializeField(schema, item, fieldType[0], writer)
})
}
Expand All @@ -53,17 +53,17 @@ function serializeField (schema, value, fieldType, writer) {
}
if (structSchema.kind === 'option') {
if (value === null) {
writer.write_u8(0)
writer.writeU8(0)
} else {
writer.write_u8(1)
writer.writeU8(1)
serializeField(schema, value, structSchema.type, writer)
}
} else if (structSchema.kind === 'struct') {
structSchema.fields.map(([fieldName, fieldType]) =>
serializeField(schema, value[fieldName], fieldType, writer)
)
} else if (structSchema.kind === 'function') {
writer.write_buffer(structSchema.ser(value))
writer.writeBuffer(structSchema.ser(value))
} else {
throw new Error(
`Unexpected schema kind: ${structSchema.kind} for ${fieldType}`
Expand Down Expand Up @@ -224,7 +224,7 @@ const signAndSendTransactionAsync = async (
const status = await account.connection.provider.status()
const [txHash, signedTx] = await nearAPI.transactions.signTransaction(
receiverId,
++accessKey.nonce,
++accessKey.accessKey.nonce,
actions,
nearAPI.utils.serialize.base_decode(status.sync_info.latest_block_hash),
account.connection.signer,
Expand Down Expand Up @@ -300,10 +300,13 @@ class BorshContract {
value: async (args) => {
args = serialize(borshSchema, d.inputFieldType, args)
const result = await backoff(10, () =>
this.account.connection.provider.query(
`call/${this.contractId}/${d.methodName}`,
nearAPI.utils.serialize.base_encode(args)
)
this.account.connection.provider.query({
request_type: 'call_function',
finality: 'final',
account_id: this.contractId,
method_name: d.methodName,
args_base64: args.toString('base64')
})
)
if (result.logs) {
this.account.printLogs(this.contractId, result.logs)
Expand Down
5 changes: 3 additions & 2 deletions utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,18 @@ async function getAccountStatus (near, accountId) {
async function accountExists (near, accountId) {
const account = new nearAPI.Account(near.connection, accountId)
try {
await account.fetchState()
await account.state()
return true
} catch (e) {
console.log(e)
return false
}
}

// Checks whether the account has the key specified in the keyStore.
async function accountHasTheKey (near, accountId) {
const account = new nearAPI.Account(near.connection, accountId)
const keyStoreKey = await near.config.deps.keyStore.getKey(
const keyStoreKey = await near.config.keyStore.getKey(
near.config.networkId,
accountId
)
Expand Down
2 changes: 1 addition & 1 deletion utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"eth-object": "https://github.com/near/eth-object#383b6ea68c7050bea4cab6950c1d5a7fa553e72b",
"eth-util-lite": "near/eth-util-lite#master",
"lodash": "^4.17.20",
"near-api-js": "^0.26.0",
"near-api-js": "^1.1.0",
"web3": "^1.6.0"
}
}
2 changes: 1 addition & 1 deletion utils/robust.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ const signAndSendTransaction = async (
let signedTx
;[txHash, signedTx] = await nearAPI.transactions.signTransaction(
receiverId,
++accessKey.nonce,
++accessKey.accessKey.nonce,
actions,
nearAPI.utils.serialize.base_decode(
status.sync_info.latest_block_hash
Expand Down
6 changes: 3 additions & 3 deletions utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const PROJECT_KEY_DIR = './neardev'
const DEFAULT_GAS = 1000000

async function setupNear (config) {
const deps = await createLocalKeyStore(config.networkId, config.keyPath)
const keyStore = await createLocalKeyStore(config.networkId, config.keyPath)
if (config.keyPath) {
delete config.keyPath
}
return nearAPI.connect({
networkId: config.networkId,
nodeUrl: config.nearNodeUrl,
deps
keyStore
})
}

Expand Down Expand Up @@ -89,7 +89,7 @@ async function createLocalKeyStore (networkId, keyPath) {
keyStore.setKey(networkId, account.account_id, keyPair).then(() => {})
keyStores.push(keyStore)
}
return { keyStore: new nearAPI.keyStores.MergeKeyStore(keyStores) }
return new nearAPI.keyStores.MergeKeyStore(keyStores)
}

function getWeb3 (config) {
Expand Down
36 changes: 25 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.6.tgz#53344adb14617a13f6e8dd2ce28905d1c0ba3215"
integrity sha1-UzRK2xRhehP26N0s4okF0cC6MhU=

[email protected]:
version "5.2.1"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-5.2.1.tgz#0bc527a6a0d18d0aa8d5b0538ce4a77dccfa7b70"
integrity sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==

bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.11.0, bn.js@^4.11.6, bn.js@^4.11.8, bn.js@^4.11.9:
version "4.12.0"
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.12.0.tgz#775b3f278efbb9718eec7361f483fb36fbbfea88"
Expand Down Expand Up @@ -1747,6 +1752,15 @@ body-parser@^1.16.0:
raw-body "2.4.2"
type-is "~1.6.18"

borsh@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/borsh/-/borsh-0.7.0.tgz#6e9560d719d86d90dc589bca60ffc8a6c51fec2a"
integrity sha512-CLCsZGIBCFnPtkNnieW/a8wmreDmfUtjU2m9yHrzPXIlNbqVs0AQrSatSG6vdNYUqdc83tkQi2eHfF98ubzQLA==
dependencies:
bn.js "^5.2.0"
bs58 "^4.0.0"
text-encoding-utf-8 "^1.0.2"

brace-expansion@^1.1.7:
version "1.1.11"
resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd"
Expand Down Expand Up @@ -2821,7 +2835,7 @@ error-ex@^1.3.1:
dependencies:
is-arrayish "^0.2.1"

error-polyfill@^0.1.2:
error-polyfill@^0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/error-polyfill/-/error-polyfill-0.1.3.tgz#df848b61ad8834f7a5db69a70b9913df86721d15"
integrity sha512-XHJk60ufE+TG/ydwp4lilOog549iiQF2OAPhkk9DdiYWMrltz5yhDz/xnKuenNwP7gy3dsibssO5QpVhkrSzzg==
Expand Down Expand Up @@ -5863,20 +5877,20 @@ natural-compare@^1.4.0:
resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"
integrity sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=

near-api-js@^0.26.0:
version "0.26.0"
resolved "https://registry.yarnpkg.com/near-api-js/-/near-api-js-0.26.0.tgz#1d13571e0ec107aaf61b908466c38110ba5bf97b"
integrity sha512-aeRU2oWo6qKJF2oM7IcZ10vEqohxk6palTTx7LBUBsaKjF8561gBNIPhnkndhSrpsVSA9NBibX80WfOmK1tqrw==
near-api-js@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/near-api-js/-/near-api-js-1.1.0.tgz#907e807f052c1f043c6fbf28f61872de3c02235a"
integrity sha512-qYKv1mYsaDZc2uYndhS+ttDhR9+60qFc+ZjD6lWsAxr3ZskMjRwPffDGQZYhC7BRDQMe1HEbk6d5mf+TVm0Lqg==
dependencies:
"@types/bn.js" "^4.11.5"
bn.js "^5.0.0"
bn.js "5.2.1"
borsh "^0.7.0"
bs58 "^4.0.0"
depd "^2.0.0"
error-polyfill "^0.1.2"
error-polyfill "^0.1.3"
http-errors "^1.7.2"
js-sha256 "^0.9.0"
mustache "^4.0.0"
node-fetch "^2.3.0"
node-fetch "^2.6.1"
text-encoding-utf-8 "^1.0.2"
tweetnacl "^1.0.1"

Expand Down Expand Up @@ -5922,7 +5936,7 @@ node-addon-api@^2.0.0:
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.2.tgz#432cfa82962ce494b132e9d72a15b29f71ff5d32"
integrity sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==

node-fetch@^2.3.0, node-fetch@^2.6.7:
node-fetch@^2.6.1, node-fetch@^2.6.7:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
Expand Down Expand Up @@ -6810,7 +6824,7 @@ quick-lru@^5.1.1:
eth-object "https://github.com/near/eth-object#383b6ea68c7050bea4cab6950c1d5a7fa553e72b"
eth-util-lite near/eth-util-lite#master
lodash "^4.17.20"
near-api-js "^0.26.0"
near-api-js "^1.1.0"
web3 "^1.6.0"

rainbow-token-connector@near/rainbow-token-connector#134b3b6ad900d90c6f993c52f4e3edf985aec61a:
Expand Down

0 comments on commit fcab67c

Please sign in to comment.