diff --git a/contracts/core/cross_chain_manager/libs/ECCUtils/EthCrossChainUtils.sol b/contracts/core/cross_chain_manager/libs/ECCUtils/EthCrossChainUtils.sol index e0a3f1f..d53f28e 100644 --- a/contracts/core/cross_chain_manager/libs/ECCUtils/EthCrossChainUtils.sol +++ b/contracts/core/cross_chain_manager/libs/ECCUtils/EthCrossChainUtils.sol @@ -41,7 +41,7 @@ library ECCUtils { for (uint i=0; i { + if (netConfig !== undefined) { + config = netConfig + } + }).catch((err) => { + console.error(err); + process.exit(1); + }); + if (config.Name === undefined) { + config.Name = hre.network.name + } + if (config.PolyChainID === undefined) { + if (hre.config.networks[hre.network.name].polyId === undefined) { + console.error("unknown network: invalid PolyChainID".red); + process.exit(1); + } + config.PolyChainID = hre.config.networks[hre.network.name].polyId + } + if (config.Provider === undefined) { + config.Provider = hre.config.networks[hre.network.name].url + writeConfig(config) + } + if (config.Deployer === undefined) { + config.Deployer = deployer.address + } + + const LockProxy = await ethers.getContractFactory("LockProxy"); + const ProxyAdmin = await ethers.getContractFactory("ProxyAdmin"); + const RippleLockProxy = await ethers.getContractFactory("RippleLockProxy"); + const EthCrossChainData = await hre.ethers.getContractFactory("EthCrossChainData"); + const CallerFactory = await hre.ethers.getContractFactory("CallerFactoryWithAdmin"); + let EthCrossChainManagerImplementation = await hre.ethers.getContractFactory("EthCrossChainManagerImplementation"); + const EthCrossChainManager = await hre.ethers.getContractFactory("EthCrossChainManager"); + const WrapperV1 = await hre.ethers.getContractFactory("PolyWrapperV1"); + const WrapperV2 = await hre.ethers.getContractFactory("PolyWrapperV2"); + const WrapperV3 = await hre.ethers.getContractFactory("PolyWrapperV3"); + let polyId = config.PolyChainID + let eccd + let ccmi + let ccm + let cf + let lockProxy + let wrapper1 + let wrapper2 + let wrapper3 + let proxyAdmin + let rippleLockProxy + let rippleLockProxyImpl + let abiCoder = new abi.AbiCoder + let rippleName = "Poly Peg Ripple Token" + let rippleSymbol = "pXRP" + let rippleDeciamls = 6 + let rippleInitData = "0xde7ea79d" + abiCoder.encode(['string','string','uint8','address'],[rippleName,rippleSymbol,rippleDeciamls,deployer.address]).slice(2); + let rippleSalt = 2; + + console.log("\nDeploy contracts on chain with Poly_Chain_Id:".cyan, polyId); + + if (config.LockProxy === undefined) { + // deploy LockProxy + console.log("\ndeploy LockProxy ......".cyan); + lockProxy = await LockProxy.deploy(); + await lockProxy.deployed(); + console.log("LockProxy deployed to:".green, lockProxy.address.blue); + config.LockProxy = lockProxy.address + writeConfig(config) + } else { + console.log("\nLockProxy already deployed at".green, config.LockProxy.blue) + lockProxy = await LockProxy.attach(config.LockProxy) + } + + if (config.EthCrossChainData === undefined) { + // deploy EthCrossChainData + console.log("\ndeploy EthCrossChainData ......".cyan); + eccd = await EthCrossChainData.deploy(); + await eccd.deployed(); + console.log("EthCrossChainData deployed to:".green, eccd.address.blue); + config.EthCrossChainData = eccd.address + writeConfig(config) + } else { + console.log("\nEthCrossChainData already deployed at".green, config.EthCrossChainData.blue) + eccd = await EthCrossChainData.attach(config.EthCrossChainData) + } + + if (config.CallerFactory === undefined) { + // deploy CallerFactory + console.log("\ndeploy CallerFactory ......".cyan); + cf = await CallerFactory.deploy([lockProxy.address]); + await cf.deployed(); + console.log("CallerFactory deployed to:".green, cf.address.blue); + config.CallerFactory = cf.address + writeConfig(config) + } else { + console.log("\nCallerFactory already deployed at".green, config.CallerFactory.blue) + cf = await CallerFactory.attach(config.CallerFactory) + } + + if (config.EthCrossChainManagerImplementation === undefined) { + // update Const.sol + console.log("\nupdate Const.sol ......".cyan); + await updateConst(config.PolyChainID, eccd.address, cf.address); + console.log("Const.sol updated".green); + await hre.run('compile'); + + // deploy EthCrossChainManagerImplementation + console.log("\ndeploy EthCrossChainManagerImplementation ......".cyan); + EthCrossChainManagerImplementation = await hre.ethers.getContractFactory("EthCrossChainManagerImplementation"); + ccmi = await EthCrossChainManagerImplementation.deploy(); + await ccmi.deployed(); + console.log("EthCrossChainManagerImplementation deployed to:".green, ccmi.address.blue); + config.EthCrossChainManagerImplementation = ccmi.address + writeConfig(config) + } else { + console.log("\nEthCrossChainManagerImplementation already deployed at".green, config.EthCrossChainManagerImplementation.blue) + ccmi = await EthCrossChainManagerImplementation.attach(config.EthCrossChainManagerImplementation) + } + + if (config.EthCrossChainManager === undefined) { + // deploy EthCrossChainManager + console.log("\ndeploy EthCrossChainManager ......".cyan); + ccm = await EthCrossChainManager.deploy(ccmi.address,deployer.address,'0x'); + await ccm.deployed(); + console.log("EthCrossChainManager deployed to:".green, ccm.address.blue); + config.EthCrossChainManager = ccm.address + writeConfig(config) + } else { + console.log("\nEthCrossChainManager already deployed at".green, config.EthCrossChainManager.blue) + ccm = await EthCrossChainManager.attach(config.EthCrossChainManager) + } + + let eccdOwner = await eccd.owner() + // transfer ownership + if (eccdOwner == ccm.address) { + console.log("\neccd ownership already transferred".green); + } else { + console.log("\ntransfer eccd's ownership to ccm ......".cyan); + tx = await eccd.transferOwnership(ccm.address); + await tx.wait(); + console.log("ownership transferred".green); + } + + let alreadySetCCMP = await lockProxy.managerProxyContract(); + if (alreadySetCCMP == ccm.address) { + console.log("\nmanagerProxyContract already set".green); + } else { + // setup LockProxy + console.log("\nsetup LockProxy ......".cyan); + tx = await lockProxy.setManagerProxy(ccm.address); + await tx.wait(); + console.log("setManagerProxy Done".green); + } + + if (config.WrapperV1 === undefined) { + // deploy WrapperV1 + console.log("\ndeploy WrapperV1 ......".cyan); + wrapper1 = await WrapperV1.deploy(deployer.address, polyId); + await wrapper1.deployed(); + console.log("WrapperV1 deployed to:".green, wrapper1.address.blue); + config.WrapperV1 = wrapper1.address + writeConfig(config) + } else { + console.log("\nWrapperV1 already deployed at".green, config.WrapperV1.blue) + wrapper1 = await WrapperV1.attach(config.WrapperV1) + } + + let alreadySetLockProxy1 = await wrapper1.lockProxy(); + let alreadySetFeeCollector1 = await wrapper1.feeCollector(); + console.log("\nsetup WrapperV1 ......".cyan); + if (alreadySetLockProxy1 == lockProxy.address) { + console.log("wrapper1 lockProxy already set".green); + } else { + // setLockProxy + console.log("setLockProxy ......".cyan); + tx = await wrapper1.setLockProxy(lockProxy.address); + await tx.wait(); + console.log("setLockProxy Done".green); + } + if (alreadySetFeeCollector1 != "0x0000000000000000000000000000000000000000") { + console.log("wrapper1 feeCollector already set".green); + } else { + // setFeeCollector + console.log("setFeeCollector ......".cyan); + tx = await wrapper1.setFeeCollector(deployer.address); + await tx.wait(); + console.log("setFeeCollector Done".green); + } + + if (config.WrapperV2 === undefined) { + // deploy WrapperV2 + console.log("\ndeploy WrapperV2 ......".cyan); + wrapper2 = await WrapperV2.deploy(deployer.address, polyId); + await wrapper2.deployed(); + console.log("WrapperV2 deployed to:".green, wrapper2.address.blue); + config.WrapperV2 = wrapper2.address + config.Wrapper = wrapper2.address + writeConfig(config) + } else { + console.log("\nWrapperV2 already deployed at".green, config.WrapperV2.blue) + wrapper2 = await WrapperV2.attach(config.WrapperV2) + if (config.wrapper != wrapper2.address) { + config.Wrapper = wrapper2.address + writeConfig(config) + } + } + + let alreadySetLockProxy2 = await wrapper2.lockProxy(); + let alreadySetFeeCollector2 = await wrapper2.feeCollector(); + console.log("\nsetup WrapperV2 ......".cyan); + if (alreadySetLockProxy2 == lockProxy.address) { + console.log("wrapper2 lockProxy already set".green); + } else { + // setLockProxy + console.log("setLockProxy ......".cyan); + tx = await wrapper2.setLockProxy(lockProxy.address); + await tx.wait(); + console.log("nsetLockProxy Done".green); + } + if (alreadySetFeeCollector2 != "0x0000000000000000000000000000000000000000") { + console.log("wrapper2 feeCollector already set".green); + } else { + // setFeeCollector + console.log("setFeeCollector ......".cyan); + tx = await wrapper2.setFeeCollector(deployer.address); + await tx.wait(); + console.log("setFeeCollector Done".green); + } + + if (config.WrapperV3 === undefined) { + // deploy WrapperV3 + console.log("\ndeploy WrapperV3 ......".cyan); + wrapper3 = await WrapperV3.deploy(deployer.address, polyId); + await wrapper3.deployed(); + console.log("WrapperV3 deployed to:".green, wrapper3.address.blue); + config.WrapperV3 = wrapper3.address + config.Wrapper = wrapper3.address + writeConfig(config) + } else { + console.log("\nWrapperV3 already deployed at".green, config.WrapperV3.blue) + wrapper3 = await WrapperV3.attach(config.WrapperV3) + if (config.wrapper != wrapper3.address) { + config.Wrapper = wrapper3.address + writeConfig(config) + } + } + + if (config.RippleLockProxyImplementation === undefined) { + // deploy rippleLockProxy Implementation + console.log("\ndeploy RippleLockProxyImplementation ......".cyan); + rippleLockProxyImpl = await RippleLockProxy.deploy(rippleName, rippleSymbol, rippleDeciamls); + await rippleLockProxyImpl.deployed(); + console.log("RippleLockProxyImplementation deployed to:".green, rippleLockProxyImpl.address.blue); + config.RippleLockProxyImplementation = rippleLockProxyImpl.address; + writeConfig(config) + } else { + console.log("\nRippleLockProxyImplementation already deployed at".green, config.RippleLockProxyImplementation.blue) + rippleLockProxyImpl = await RippleLockProxy.attach(config.RippleLockProxyImplementation) + } + + if (config.ProxyAdmin === undefined) { + // deploy ProxyAdmin + console.log("\ndeploy ProxyAdmin ......".cyan); + proxyAdmin = await ProxyAdmin.deploy(); + await proxyAdmin.deployed(); + console.log("ProxyAdmin deployed to:".green, proxyAdmin.address.blue); + config.ProxyAdmin = proxyAdmin.address; + writeConfig(config) + } else { + console.log("\nProxyAdmin already deployed at".green, config.ProxyAdmin.blue) + proxyAdmin = await ProxyAdmin.attach(config.ProxyAdmin) + } + + if (config.RippleLockProxy === undefined) { + // deploy rippleLockProxy + console.log("\ndeploy RippleLockProxy......".cyan); + tx = await cf.deploy(rippleSalt, rippleLockProxyImpl.address, proxyAdmin.address, rippleInitData); + await tx.wait(); + let rippleLockProxyAddress = await cf.getDeploymentAddress(rippleSalt, deployer.address); + rippleLockProxy = await RippleLockProxy.attach(rippleLockProxyAddress); + console.log("RippleLockProxy deployed to:".green, rippleLockProxy.address.blue); + config.RippleLockProxy = rippleLockProxy.address; + writeConfig(config) + } else { + console.log("\nRippleLockProxy already deployed at".green, config.RippleLockProxy.blue) + rippleLockProxy = await RippleLockProxy.attach(config.RippleLockProxy) + } + let xrp = await rippleLockProxy.token(); + console.log("\nXRP-Token deployed at".green, xrp.blue); + + let alreadySetCCMPRipple = await rippleLockProxy.managerProxyContract(); + if (alreadySetCCMPRipple == ccm.address) { + console.log("\nmanagerContract of ripple LockProxy already set".green); + } else { + // setup RippleLockProxy + console.log("\nsetup RippleLockProxy ......".cyan); + tx = await rippleLockProxy.setManager(ccm.address); + await tx.wait(); + console.log("setManager Done".green); + } + + let alreadyAddLockProxy3 = await wrapper3.isValidLockProxy(lockProxy.address); + let alreadySetFeeCollector3 = await wrapper3.feeCollector(); + let alreadyAddRippleLockProxy3 = await wrapper3.isValidLockProxy(rippleLockProxy.address); + console.log("\nsetup WrapperV3 ......".cyan); + if (alreadyAddLockProxy3) { + console.log("wrapper3 lockProxy already add".green); + } else { + // addLockProxy + console.log("addLockProxy ......".cyan); + tx = await wrapper3.addLockProxy(lockProxy.address); + await tx.wait(); + console.log("addLockProxy Done".green); + } + if (alreadyAddRippleLockProxy3) { + console.log("wrapper3 rippleLockProxy already add".green); + } else { + // addLockProxy + console.log("add RippleLockProxy ......".cyan); + tx = await wrapper3.addLockProxy(rippleLockProxy.address); + await tx.wait(); + console.log("add RippleLockProxy Done".green); + } + if (alreadySetFeeCollector3 != "0x0000000000000000000000000000000000000000") { + console.log("wrapper3 feeCollector already set".green); + } else { + // setFeeCollector + console.log("setFeeCollector ......".cyan); + tx = await wrapper3.setFeeCollector(deployer.address); + await tx.wait(); + console.log("setFeeCollector Done".green); + } + + // write config + console.log("constract output:\n".cyan,config); + await writeConfig(config) + console.log("\nwrite config done\n".green); + + console.log("\nDone.\n".magenta); +} + +async function updateConst(polyChainId, eccd, callerFactory) { + + fs.writeFileSync('./contracts/core/cross_chain_manager/logic/Const.sol', + 'pragma solidity ^0.5.0;\n'+ + 'contract Const {\n'+ + ' bytes constant ZionCrossChainManagerAddress = hex"0000000000000000000000000000000000001003"; \n'+ + // ' bytes constant ZionCrossChainManagerAddress = hex"5747C05FF236F8d18BB21Bc02ecc389deF853cae"; \n'+ + ' \n'+ + ' address constant EthCrossChainDataAddress = '+eccd+'; \n'+ + ' address constant EthCrossChainCallerFactoryAddress = '+callerFactory+'; \n'+ + ' uint constant chainId = '+polyChainId+'; \n}', + function(err) { + if (err) { + console.error(err); + process.exit(1); + } + }); +} + +async function readConfig(networkName) { + let jsonData + try { + jsonData = fs.readFileSync(configPath) + } catch(err) { + if (err.code == 'ENOENT') { + createEmptyConfig() + return + }else{ + console.error(err); + process.exit(1); + } + } + if (jsonData === undefined) { + return + } + var json=JSON.parse(jsonData.toString()) + if (json.Networks === undefined) { + return + } + for (let i=0; i{ + if (err) { + console.error(err); + process.exit(1); + }else{ + previous=data.toString(); + } + }); + var json = JSON.parse(data.toString()) + var writeIndex = json.Networks.length + for (let i=0; i process.exit(0)) + .catch((err) => { + console.error(err) + process.exit(1) + }); diff --git a/scripts/deployBase.js b/scripts/deployBase.js deleted file mode 100644 index b72c407..0000000 --- a/scripts/deployBase.js +++ /dev/null @@ -1,144 +0,0 @@ -const { ethers } = require("hardhat"); -const hre = require("hardhat"); -const fs = require("fs"); -const Web3 = require("web3"); -const colors = require('colors'); -hre.web3 = new Web3(hre.network.provider); - -async function main() { - - [deployer] = await hre.ethers.getSigners(); - - // check if given networkId is registered - await getPolyChainId().then((polyId) => { - console.log("\nDeploy EthCrossChainManager on chain with Poly_Chain_Id:".cyan, polyId); - }).catch((error) => { - throw error; - });; - - console.log("Start , deployer:".cyan, deployer.address.blue); - - await hre.run('compile'); - - // deploy EthCrossChainData - console.log("\ndeploy EthCrossChainData ......".cyan); - const ECCD = await hre.ethers.getContractFactory("EthCrossChainData"); - const eccd = await ECCD.deploy(); - await eccd.deployed(); - console.log("EthCrossChainData deployed to:".green, eccd.address.blue); - - // deploy CallerFactory - console.log("\ndeploy CallerFactory ......".cyan); - const CallerFactory = await hre.ethers.getContractFactory("CallerFactory"); - const cf = await CallerFactory.deploy(); - await cf.deployed(); - console.log("CallerFactory deployed to:".green, cf.address.blue); - - // update Const.sol - console.log("\nupdate Const.sol ......".cyan); - await updateConst(eccd.address, cf.address); - console.log("Const.sol updated".green); - await hre.run('compile'); - - // deploy EthCrossChainManagerImplementation - console.log("\ndeploy EthCrossChainManagerImplementation ......".cyan); - const CCM = await hre.ethers.getContractFactory("EthCrossChainManagerImplementation"); - const ccm = await CCM.deploy(); - await ccm.deployed(); - console.log("EthCrossChainManagerImplementation deployed to:".green, ccm.address.blue); - - // deploy EthCrossChainManager - console.log("\ndeploy EthCrossChainManager ......".cyan); - const CCMP = await hre.ethers.getContractFactory("EthCrossChainManager"); - const ccmp = await CCMP.deploy(ccm.address,deployer.address,'0x'); - await ccmp.deployed(); - console.log("EthCrossChainManager deployed to:".green, ccmp.address.blue); - - // transfer ownership - console.log("\ntransfer eccd's ownership to ccm ......".cyan); - await eccd.transferOwnership(ccmp.address); - console.log("ownership transferred".green); - - console.log("\nDone.\n".magenta); - -} - -function verifyAtEtherscan(address, constructorArguments) { - return hre.run("verify:verify", { - address: address, - constructorArguments: constructorArguments, - }); -} - -async function updateConst(eccd, callerFactory) { - const polyChainId = await getPolyChainId(); - - await fs.writeFile('./contracts/core/cross_chain_manager/logic/Const.sol', - 'pragma solidity ^0.5.0;\n'+ - 'contract Const {\n'+ - ' bytes constant ZionCrossChainManagerAddress = hex"5747C05FF236F8d18BB21Bc02ecc389deF853cae"; \n'+ - ' bytes constant ZionValidaterManagerAddress = hex"A4Bf827047a08510722B2d62e668a72FCCFa232C"; \n'+ - ' address constant EthCrossChainDataAddress = '+eccd+'; \n'+ - ' address constant EthCrossChainCallerFactoryAddress = '+callerFactory+'; \n'+ - ' uint constant chainId = '+polyChainId+'; \n}', - function(err) { - if (err) { - console.error(err); - process.exit(1); - } - }); -} - -async function getPolyChainId() { - const chainId = await hre.web3.eth.getChainId(); - switch (chainId) { - - // mainnet - case 1: // eth-main - return 2; - case 56: // bsc-main - return 6; - case 128: // heco-main - return 7; - case 137: // polygon-main - return 17; - case 66: // ok-main - return 12; - case 1718: // plt-main - return 8; - - // testnet - case 3: // eth-test - return 2; - case 97: // bsc-test - return 79; - case 256: // heco-test - return 7; - case 80001: // polygon-test - return 202; - case 65: // ok-test - return 200; - case 101: // plt-test - return 107; - case 421611: // arbitrum-test - return 205; - - // hardhat devnet - case 31337: - return 77777; - - // unknown chainid - default: - throw new Error("fail to get Poly_Chain_Id, unknown Network_Id: "+chainId); - } -} - -// We recommend this pattern to be able to use async/await everywhere -// and properly handle errors. -main() - .then(() => process.exit(0)) - .catch((error) => { - console.error(error); - process.exit(1); - }); - diff --git a/test/ECCUtilsTest.js b/test/ECCUtilsTest.js index 412619f..0c395e4 100644 --- a/test/ECCUtilsTest.js +++ b/test/ECCUtilsTest.js @@ -1,4 +1,4 @@ -const { ethers } = require("hardhat"); +const ethers = require("@nomiclabs/hardhat-ethers"); const hre = require("hardhat"); const Web3 = require("web3"); const { expect } = require("chai"); @@ -17,8 +17,8 @@ describe.only("ECCUtils", function () { let addrs; beforeEach("Should init", async function () { - ECCUtilsMock = await ethers.getContractFactory("ECCUtilsMock"); - [addr1, addr2, ...addrs] = await ethers.getSigners(); + ECCUtilsMock = await hre.ethers.getContractFactory("ECCUtilsMock"); + [addr1, addr2, ...addrs] = await hre.ethers.getSigners(); eccu = await ECCUtilsMock.deploy(); }); @@ -77,16 +77,16 @@ describe.only("ECCUtils", function () { }); describe("verifyHeader", function () { - // let header = '0xf90271a02b2864068eeb4145b64f4ac04f5f4500e16b758a2b6d1795a7539082656e323ca01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794258af48e28e4a6846e931ddff8e1cdf8579821e5a0bfc1711d4a46f45c2422bc0c97c3a3e69ab5429b340f4a6f92224bfe0e1fed4da056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010d84fcc4db9f8084614d3d34b87bd983010a04846765746888676f312e31362e328664617277696e000000000000f859f85494258af48e28e4a6846e931ddff8e1cdf8579821e5948c09d936a1b408d6e0afaa537ba4e06c4504a0ae94c095448424a5ecd5ca7ccdadfaad127a9d7e88ec94d47a4e56e9262543db39d9203cf1a2e53735f83480c080a063746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365880000000000000000'; - let headerHash = '0xcc558e6bf91b122eb2dc5fd68a3ca44198a78f2871c32315436c9afc147b108e'; - let validators = ['0xD47a4e56e9262543Db39d9203CF1a2e53735f834','0xC095448424A5ECd5cA7CcDaDFaAD127a9d7E88ec','0x8c09D936a1B408D6e0afAA537ba4E06c4504a0AE','0x258af48e28e4a6846e931ddff8e1cdf8579821e5']; - let rawSealsValid1 = '0xf8c9b8417857f807dda72d9ab2062305dbc0837291ddd06e4c0faa86b98d644ef3ad48c15c9db9ee68d80175dc007c2724b40508bef467ac29ef98fc924ee5f6e318fe1d00b84157d201dec3551d8333a75ff69c8cce5e991c26c5e7cc0d30fd68512c95034fa65ad3f496967c333de36c19d0d1cf05642106108cd7da4b4ea83a32b125478c6001b84108c2d0c8988a3d0e84eb2385f662fd1469578552a84bc0f354818524a23c6c332b375216998855d143493352a090439de03a98cdad8569bb5af4486916c0143d00'; - let rawSealsValid2 = '0xf9010cb8417857f807dda72d9ab2062305dbc0837291ddd06e4c0faa86b98d644ef3ad48c15c9db9ee68d80175dc007c2724b40508bef467ac29ef98fc924ee5f6e318fe1d00b84157d201dec3551d8333a75ff69c8cce5e991c26c5e7cc0d30fd68512c95034fa65ad3f496967c333de36c19d0d1cf05642106108cd7da4b4ea83a32b125478c6001b84108c2d0c8988a3d0e84eb2385f662fd1469578552a84bc0f354818524a23c6c332b375216998855d143493352a090439de03a98cdad8569bb5af4486916c0143d00b841460f2f90d7f07fb99c0990ab38d15fc2fd3868239fa0be795db0f5b9240bdbea67ec09cff65cb125a171cb98a5c7c6f55ce0bda8086079dc23f777ebf4fbfc0e00'; - let rawSealsInvalid1 = '0xf886b8417857f807dda72d9ab2062305dbc0837291ddd06e4c0faa86b98d644ef3ad48c15c9db9ee68d80175dc007c2724b40508bef467ac29ef98fc924ee5f6e318fe1d00b84157d201dec3551d8333a75ff69c8cce5e991c26c5e7cc0d30fd68512c95034fa65ad3f496967c333de36c19d0d1cf05642106108cd7da4b4ea83a32b125478c6001'; - let rawSealsInvalid2 = '0xf8c9b8417857f807dda72d9ab2062305dbc0837291ddd06e4c0faa86b98d644ef3ad48c15c9db9ee68d80175dc007c2724b40508bef467ac29ef98fc924ee5f6e318fe1d00b84157d201dec3551d8333a75ff69c8cce5e991c26c5e7cc0d30fd68512c95034fa65ad3f496967c333de36c19d0d1cf05642106108cd7da4b4ea83a32b125478c6001b841460f2f90d7f07fb99c0990ab38d15fc2fd3868239fa0be795db0f5b9240bdbea67ec09cff65cb125a171cb98a5c7c6f55ce0bda8086079dc23f777ebf4fbfc0e00'; - let rawSealsInvalid3 = '0xf8c9b8417857f807dda72d9ab2062305dbc0837291ddd06e4c0faa86b98d644ef3ad48c15c9db9ee68d80175dc007c2724b40508bef467ac29ef98fc924ee5f6e318fe1d00b84157d201dec3551d8333a75ff69c8cce5e991c26c5e7cc0d30fd68512c95034fa65ad3f496967c333de36c19d0d1cf05642106108cd7da4b4ea83a32b125478c6001b8417857f807dda72d9ab2062305dbc0837291ddd06e4c0faa86b98d644ef3ad48c15c9db9ee68d80175dc007c2724b40508bef467ac29ef98fc924ee5f6e318fe1d00'; - let rawSealsInvalid4 = '0xf9010cb8417857f807dda72d9ab2062305dbc0837291ddd06e4c0faa86b98d644ef3ad48c15c9db9ee68d80175dc007c2724b40508bef467ac29ef98fc924ee5f6e318fe1d00b84157d201dec3551d8333a75ff69c8cce5e991c26c5e7cc0d30fd68512c95034fa65ad3f496967c333de36c19d0d1cf05642106108cd7da4b4ea83a32b125478c6001b8417857f807dda72d9ab2062305dbc0837291ddd06e4c0faa86b98d644ef3ad48c15c9db9ee68d80175dc007c2724b40508bef467ac29ef98fc924ee5f6e318fe1d00b8410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'; - + // let header = '0xf90228a0df4418b616c081d43ed9fc95f0d4aade6dd53b8142501c2b50194ff657b8c5faa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794258af48e28e4a6846e931ddff8e1cdf8579821e5a065d89a0ab347c7447eb652cbc75bc47259fada45a1e20bd617d23b22433a7109a0cb1b6e0b67e482d7449e8fc0fc36b7f9ce5a9fb0cf45f6a9199a5d9e12216d5ea0d4e4d938901e00ea4da08917593dba522a19b68413162444389bb35251dd96e3b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001830f0cc08411e1a30083029bf88463f34193ad0000000000000000000000000000000000000000000000000000000000000000cc830f03c0830f0f78c080c080a063746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365880000000000000000'; + let headerHash = '0x3783ca1fac023336e50f0bfc01a66f98b6c54a7c406c22b17159e775928f2e67'; + let validators = ['0x258af48e28e4a6846e931ddff8e1cdf8579821e5','0x6a708455c8777630aac9d1e7702d13f7a865b27c','0x8c09d936a1b408d6e0afaa537ba4e06c4504a0ae','0xad3bf5ed640cc72f37bd21d64a65c3c756e9c88c']; + let rawSealsValid1 = '0xf8c9b841a223e26e4a97a82233a12364fc08ee186309ac43b6218d6437b21f67752cf2333e931dae8053b5abb0220b0a66f24a6945c2762817e6ae2b3c1f61ff4296690a01b8415c7d47956a9e7044d598e328e5a53f2458a8424aa1302687c2a7faf307b22ecf22d531d5621b3018789c4da719e3cb602b714171eb519d0dcab8dbb023cd404401b841ef9c48bfb1ed827ad6a966d366679139167164045430694b80d77492eb78331d49a8a48c3b61991fe156b2426704dfd2bfd0c768fe22b815418c911d08e33d4501'; + let rawSealsValid2 = '0xf9010cb841a223e26e4a97a82233a12364fc08ee186309ac43b6218d6437b21f67752cf2333e931dae8053b5abb0220b0a66f24a6945c2762817e6ae2b3c1f61ff4296690a01b8415c7d47956a9e7044d598e328e5a53f2458a8424aa1302687c2a7faf307b22ecf22d531d5621b3018789c4da719e3cb602b714171eb519d0dcab8dbb023cd404401b841ef9c48bfb1ed827ad6a966d366679139167164045430694b80d77492eb78331d49a8a48c3b61991fe156b2426704dfd2bfd0c768fe22b815418c911d08e33d4501b84159d8a54f0840f9bcbfba3e881c74191f0a1593cdc0551d1fdf723cda10ac24af57e1c4278324ec9dc163752148005e975a78265ad688b81c4cc01524f59f811900'; + let rawSealsInvalid1 = '0xf886b8415c7d47956a9e7044d598e328e5a53f2458a8424aa1302687c2a7faf307b22ecf22d531d5621b3018789c4da719e3cb602b714171eb519d0dcab8dbb023cd404401b841ef9c48bfb1ed827ad6a966d366679139167164045430694b80d77492eb78331d49a8a48c3b61991fe156b2426704dfd2bfd0c768fe22b815418c911d08e33d4501'; + let rawSealsInvalid2 = '0xf8c9b8415c7d47956a9e7044d598e328e5a53f2458a8424aa1302687c2a7faf307b22ecf22d531d5621b3018789c4da719e3cb602b714171eb519d0dcab8dbb023cd404401b841ef9c48bfb1ed827ad6a966d366679139167164045430694b80d77492eb78331d49a8a48c3b61991fe156b2426704dfd2bfd0c768fe22b815418c911d08e33d4501b84159d8a54f0840f9bcbfba3e881c74191f0a1593cdc0551d1fdf723cda10ac24af57e1c4278324ec9dc163752148005e975a78265ad688b81c4cc01524f59f811900'; + let rawSealsInvalid3 = '0xf8c9b8415c7d47956a9e7044d598e328e5a53f2458a8424aa1302687c2a7faf307b22ecf22d531d5621b3018789c4da719e3cb602b714171eb519d0dcab8dbb023cd404401b841ef9c48bfb1ed827ad6a966d366679139167164045430694b80d77492eb78331d49a8a48c3b61991fe156b2426704dfd2bfd0c768fe22b815418c911d08e33d4501b841ef9c48bfb1ed827ad6a966d366679139167164045430694b80d77492eb78331d49a8a48c3b61991fe156b2426704dfd2bfd0c768fe22b815418c911d08e33d4501'; + let rawSealsInvalid4 = '0xf9010cb841a223e26e4a97a82233a12364fc08ee186309ac43b6218d6437b21f67752cf2333e931dae8053b5abb0220b0a66f24a6945c2762817e6ae2b3c1f61ff4296690a01b8415c7d47956a9e7044d598e328e5a53f2458a8424aa1302687c2a7faf307b22ecf22d531d5621b3018789c4da719e3cb602b714171eb519d0dcab8dbb023cd404401b841ef9c48bfb1ed827ad6a966d366679139167164045430694b80d77492eb78331d49a8a48c3b61991fe156b2426704dfd2bfd0c768fe22b815418c911d08e33d4501b8410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'; + it("Should return true while there is enough valid seals", async function () { expect(await eccu.verifyHeader(headerHash, rawSealsValid1, validators)).to.equal(true); }); @@ -189,7 +189,7 @@ describe.only("ECCUtils", function () { it("Should return block.root and block.number", async function () { let header = await eccu.decodeHeader(rawHeader); expect(header.root).to.equal(root); - expect(header.number).to.equal(number); + expect(Number(header.number)).to.equal(number); }); // TODO: update rawHeader @@ -248,7 +248,7 @@ describe.only("ECCUtils", function () { }); it("bytesToUint256", async function () { - expect(await eccu.bytesToUint256(_uint256Hex)).to.equal(_uint256); + expect(Number(await eccu.bytesToUint256(_uint256Hex))).to.equal(_uint256); await expect(eccu.bytesToUint256(_address)).to.be.revertedWith("bytes length is not 32."); // invalid length }); @@ -308,7 +308,7 @@ describe.only("ECCUtils", function () { expect(res.sourceTxHash).to.equal(sourceTxHash); expect(res.crossChainId).to.equal(crossChainId); expect(res.fromContract).to.equal(fromContract); - expect(res.toChainId).to.equal(toChainId); + expect(Number(res.toChainId)).to.equal(toChainId); expect(res.toContract).to.equal(toContract); expect(res.method).to.equal(method); expect(res.args).to.equal(args); @@ -317,11 +317,11 @@ describe.only("ECCUtils", function () { it("decodeCrossTx", async function () { let res = await eccu.decodeCrossTx(rawCrossTxBytes); expect(res.zionTxHash).to.equal(zionTxHash); - expect(res.fromChainID).to.equal(fromChainID); + expect(Number(res.fromChainID)).to.equal(fromChainID); expect(res.sourceTxHash).to.equal(sourceTxHash); expect(res.crossChainId).to.equal(crossChainId); expect(res.fromContract).to.equal(fromContract); - expect(res.toChainId).to.equal(toChainId); + expect(Number(res.toChainId)).to.equal(toChainId); expect(res.toContract).to.equal(toContract); expect(res.method).to.equal(method); expect(res.args).to.equal(args); @@ -361,7 +361,7 @@ describe.only("ECCUtils", function () { } let output = await eccu.rlpGetNextBytes(raw,offset); expect(output.res).to.equal(res); - expect(output._offset).to.equal(_offset); + expect(Number(output._offset)).to.equal(_offset); expect(output._raw).to.equal(raw); } await rlpGetNextBytesTest('0x0000000080',0x24,'0x',0x25,false); // 0 byte @@ -378,7 +378,7 @@ describe.only("ECCUtils", function () { } let output = await eccu.rlpGetNextBytes32(raw,offset); expect(output.res).to.equal(res); - expect(output._offset).to.equal(_offset); + expect(Number(output._offset)).to.equal(_offset); expect(output._raw).to.equal(raw); } await rlpGetNextBytes32Test('0x0000000080',0x24,'0x0000000000000000000000000000000000000000000000000000000000000000',0x25,false); // 0 byte @@ -395,7 +395,7 @@ describe.only("ECCUtils", function () { } let output = await eccu.rlpGetNextAddress(raw,offset); expect(output.res).to.equal(res); - expect(output._offset).to.equal(_offset); + expect(Number(output._offset)).to.equal(_offset); expect(output._raw).to.equal(raw); } await rlpGetNextAddressTest('0x0000000080',0x24,'0x0000000000000000000000000000000000000000',0x25,false); // 0 byte @@ -411,8 +411,8 @@ describe.only("ECCUtils", function () { return } let output = await eccu.rlpGetNextUint64(raw,offset); - expect(output.res).to.equal(res); - expect(output._offset).to.equal(_offset); + expect(Number(output.res)).to.equal(res); + expect(Number(output._offset)).to.equal(_offset); expect(output._raw).to.equal(raw); } await rlpGetNextUint64Test('0x0000000080',0x24,0x0,0x25,false); // 0 byte @@ -428,8 +428,8 @@ describe.only("ECCUtils", function () { return } let output = await eccu.rlpGetNextUint256(raw,offset); - expect(output.res).to.equal(res); - expect(output._offset).to.equal(_offset); + expect(Number(output.res)).to.equal(res); + expect(Number(output._offset)).to.equal(_offset); expect(output._raw).to.equal(raw); } await rlpGetNextUint256Test('0x0000000080',0x24,0x0,0x25,false); // 0 byte @@ -442,7 +442,7 @@ describe.only("ECCUtils", function () { let rlpSplitTest = async function (raw, offset, res, offset_) { let output = await eccu.rlpSplit(raw,offset); expect(output.res).to.equal(res); - expect(output.offset_).to.equal(offset_); + expect(Number(output.offset_)).to.equal(offset_); } let raw = '0x77'+'82ffff'+'b803ffffff'+'c480808080'+'f8058080808080'; let offset1 = 0x20; @@ -468,7 +468,7 @@ describe.only("ECCUtils", function () { it("rlpReadKind", async function () { let rlpReadKindTest = async function (raw, offset, size, offset_) { let output = await eccu.rlpReadKind(raw, offset); - expect(output.size).to.equal(size); + expect(Number(output.size)).to.equal(size); expect(Number(output.offset_)+size).to.equal(offset_); } let raw = '0x77'+'82ffff'+'b803ffffff'+'c480808080'+'f8058080808080'; @@ -547,7 +547,7 @@ describe.only("ECCUtils", function () { let b1 = 0x0a; let res = await eccu.takeOneByte(raw); expect(res.buf).to.equal(slice); - expect(res.i).to.equal(b1); + expect(Number(res.i)).to.equal(b1); }); it("Should fail if input is empty", async function () {