-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cross chain testing scripts. (#2033)
* Rework to use config endpoint. * Returning sim test. * Revert IDE flag. * Adding l2 message bus. * Dumping progress. * Dumping debug scripts. * UAT version. * Potential fix. * Fix for rpc error. * Committing generated contracts. * UAT changes. * Added dev testnet to the network config. * Adding back skip flag. * Addressed PR comments. * PR comment. --------- Co-authored-by: StefanIliev545 <[email protected]>
- Loading branch information
1 parent
9925408
commit 56fee0e
Showing
13 changed files
with
293 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
contracts/deployment_scripts/testing/002_access_list_test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import {HardhatRuntimeEnvironment} from 'hardhat/types'; | ||
import {DeployFunction} from 'hardhat-deploy/types'; | ||
import { Receipt } from 'hardhat-deploy/dist/types'; | ||
|
||
|
||
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
return; | ||
const l2Network = hre; | ||
const {deployer} = await hre.getNamedAccounts(); | ||
|
||
const gcb = await l2Network.deployments.deploy("GasConsumerBalance", { | ||
from: deployer, | ||
log: true | ||
}) | ||
|
||
const signer = await hre.ethers.getSigner(deployer); | ||
|
||
const gasConsumerBalance = await hre.ethers.getContractAt("GasConsumerBalance", gcb.address) | ||
const gasConsumer = await gasConsumerBalance.connect(signer) | ||
|
||
|
||
const tx = await gasConsumer.getFunction("resetOwner").populateTransaction(deployer); | ||
tx.accessList = [ | ||
{ | ||
address: gcb.address, | ||
storageKeys: [] | ||
}, | ||
]; | ||
const resp = await signer.sendTransaction(tx); | ||
const receipt = await resp.wait(); | ||
console.log(`Receipt.Status=${receipt.status}`); | ||
}; | ||
|
||
|
||
export default func; | ||
func.tags = ['GasDebug']; |
119 changes: 119 additions & 0 deletions
119
contracts/deployment_scripts/testing/003_simple_withdrawal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import {EthereumProvider, HardhatRuntimeEnvironment} from 'hardhat/types'; | ||
import {DeployFunction} from 'hardhat-deploy/types'; | ||
import { Receipt } from 'hardhat-deploy/dist/types'; | ||
import { StandardMerkleTree } from "@openzeppelin/merkle-tree"; | ||
import { keccak256 } from 'ethers'; | ||
import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/hardhat-ethers-provider'; | ||
|
||
function process_value_transfer(ethers, value_transfer) { | ||
const abiTypes = ['address', 'address', 'uint256', 'uint64']; | ||
const msg = [ | ||
value_transfer['args'].sender, value_transfer['args'].receiver, | ||
value_transfer['args'].amount.toString(), value_transfer['args'].sequence.toString() | ||
] | ||
|
||
const abiCoder = ethers.AbiCoder.defaultAbiCoder(); | ||
const encodedMsg = abiCoder.encode(abiTypes, msg); | ||
return [msg, ethers.keccak256(encodedMsg)]; | ||
} | ||
|
||
|
||
function decode_base64(base64String) { | ||
let jsonString = atob(base64String); | ||
return JSON.parse(jsonString); | ||
} | ||
|
||
|
||
async function sleep(ms: number) { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, ms); | ||
}); | ||
} | ||
async function waitForRootPublished(management, msg, proof, root, provider: EthereumProvider, interval = 5000, timeout = 120000) { | ||
var gas_estimate = null | ||
const l1Ethers = new HardhatEthersProvider(provider, "layer1") | ||
|
||
const startTime = Date.now(); | ||
while (gas_estimate === null) { | ||
try { | ||
console.log(`Extracting native value from cross chain message for root ${root}`) | ||
const tx = await management.getFunction('ExtractNativeValue').populateTransaction(msg, proof, root, {} ) | ||
console.log(`Tx to = ${tx.to}`) | ||
gas_estimate = await l1Ethers.estimateGas(tx) | ||
} catch (error) { | ||
console.log(`Estimate gas threw error : ${error}`) | ||
} | ||
if (Date.now() - startTime >= timeout) { | ||
console.log(`Timed out waiting for the estimate gas to return`) | ||
break | ||
} | ||
await sleep(interval) | ||
} | ||
console.log(`Estimation took ${Date.now() - startTime} ms`) | ||
return gas_estimate | ||
} | ||
|
||
|
||
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
const l2Network = hre; | ||
const {deployer} = await hre.getNamedAccounts(); | ||
|
||
var mbusBase = await hre.ethers.getContractAt("MessageBus", "0x526c84529b2b8c11f57d93d3f5537aca3aecef9b"); | ||
const mbus = mbusBase.connect(await hre.ethers.provider.getSigner(deployer)); | ||
const tx = await mbus.getFunction("sendValueToL2").send(deployer, 1000, { value: 1000}); | ||
const receipt = await tx.wait() | ||
console.log(`003_simple_withdrawal: Cross Chain send receipt status = ${receipt.status}`); | ||
|
||
const block = await hre.ethers.provider.send('eth_getBlockByHash', [receipt.blockHash, true]); | ||
console.log(`Block received: ${block.number}`) | ||
|
||
|
||
const value_transfer = mbus.interface.parseLog(receipt.logs[0]); | ||
const _processed_value_transfer = process_value_transfer(hre.ethers, value_transfer) | ||
const msg = _processed_value_transfer[0] | ||
const msgHash = _processed_value_transfer[1] | ||
const decoded = decode_base64(block.crossChainTree) | ||
|
||
console.log(` Sender: ${value_transfer['args'].sender}`) | ||
console.log(` Receiver: ${value_transfer['args'].receiver}`) | ||
console.log(` Amount: ${value_transfer['args'].amount}`) | ||
console.log(` Sequence: ${value_transfer['args'].sequence}`) | ||
console.log(` VTrans Hash: ${msgHash}`) | ||
console.log(` XChain tree: ${decoded}`) | ||
|
||
if (decoded[0][1] != msgHash) { | ||
console.error('Value transfer hash is not in the xchain tree!'); | ||
return; | ||
} | ||
|
||
const tree = StandardMerkleTree.of(decoded, ["string", "bytes32"]); | ||
const proof = tree.getProof(['v',msgHash]) | ||
console.log(` Merkle root: ${tree.root}`) | ||
console.log(` Merkle proof: ${JSON.stringify(proof, null,2)}`) | ||
|
||
if (block.crossChainTreeHash != tree.root) { | ||
console.error('Constructed merkle root matches block crossChainTreeHash'); | ||
return | ||
} | ||
|
||
|
||
//const networkConfig : any = await hre.network.provider.request({method: 'net_config'}); | ||
const mgmtContractAddress = "0x946600AF6893Ee818CC7CC2dEC4D0A0bF91C9817" // networkConfig.ManagementContractAddress; | ||
const messageBusAddress = "0x68e95924f22Be35386A8aE0240f8885967d452D6" //networkConfig.MessageBusAddress; | ||
|
||
const l1Accounts = await hre.companionNetworks.layer1.getNamedAccounts() | ||
const fundTx = await hre.companionNetworks.layer1.deployments.rawTx({ | ||
from: l1Accounts.deployer, | ||
to: messageBusAddress, | ||
value: "1000", | ||
}) | ||
console.log(`Message bus funding status = ${fundTx.status}`) | ||
|
||
var managementContract = await hre.ethers.getContractAt("ManagementContract", mgmtContractAddress); | ||
const estimation = await waitForRootPublished(managementContract, msg, proof, tree.root, hre.companionNetworks.layer1.provider) | ||
console.log(`Estimation for native value extraction = ${estimation}`) | ||
}; | ||
|
||
|
||
export default func; | ||
func.tags = ['GasDebug']; |
25 changes: 23 additions & 2 deletions
25
contracts/generated/GasConsumerBalance/GasConsumerBalance.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.