Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
flatten before verification (#828)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrasiuk authored Feb 4, 2022
1 parent 99230af commit d39c024
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ethers-etherscan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ keywords = ["ethereum", "web3", "etherscan", "ethers"]

[dependencies]
ethers-core = { version = "^0.6.0", path = "../ethers-core", default-features = false }
ethers-solc = { version = "^0.1.0", path = "../ethers-solc", default-features = false }
reqwest = { version = "0.11.9", default-features = false, features = ["json"] }
serde = { version = "1.0.124", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.64", default-features = false }
Expand Down
15 changes: 15 additions & 0 deletions ethers-etherscan/resources/IERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
interface IERC20 {
function totalSupply() external view returns(uint);

function balanceOf(address account) external view returns(uint);

function transfer(address recipient, uint amount) external returns(bool);

function allowance(address owner, address spender) external view returns(uint);

function approve(address spender, uint amount) external returns(bool);

function transferFrom(address sender, address recipient, uint amount) external returns(bool);
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
}
19 changes: 3 additions & 16 deletions ethers-etherscan/resources/UniswapExchange.sol
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
/**
*Submitted for verification at Etherscan.io on 2021-10-03
*/
* Submitted for verification at Etherscan.io on 2021-10-03
*/

pragma solidity ^0.5.17;
interface IERC20 {
function totalSupply() external view returns(uint);

function balanceOf(address account) external view returns(uint);

function transfer(address recipient, uint amount) external returns(bool);

function allowance(address owner, address spender) external view returns(uint);

function approve(address spender, uint amount) external returns(bool);

function transferFrom(address sender, address recipient, uint amount) external returns(bool);
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
}
import "./IERC20.sol";

library Address {
function isContract(address account) internal view returns(bool) {
Expand Down
25 changes: 16 additions & 9 deletions ethers-etherscan/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,12 @@ impl Client {

#[cfg(test)]
mod tests {
use std::time::Duration;
use std::{path::PathBuf, time::Duration};

use serial_test::serial;

use ethers_core::types::Chain;
use ethers_solc::{MinimalCombinedArtifacts, Project, ProjectPathsConfig};

use crate::{contract::VerifyContract, tests::run_at_least_duration, Client};

Expand Down Expand Up @@ -302,26 +303,32 @@ mod tests {

#[tokio::test]
#[serial]
#[ignore]
async fn can_verify_contract() {
async fn can_flatten_and_verify_contract() {
run_at_least_duration(Duration::from_millis(250), async {
// TODO this needs further investigation
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("resources");
let paths = ProjectPathsConfig::builder()
.sources(&root)
.build()
.expect("failed to resolve project paths");
let project = Project::<MinimalCombinedArtifacts>::builder()
.paths(paths)
.build()
.expect("failed to build the project");

// https://etherscan.io/address/0x9e744c9115b74834c0f33f4097f40c02a9ac5c33#code
let contract = include_str!("../resources/UniswapExchange.sol");
let address = "0x9e744c9115b74834c0f33f4097f40c02a9ac5c33".parse().unwrap();
let compiler_version = "v0.5.17+commit.d19bba13";
let constructor_args = "0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000007596179537761700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035941590000000000000000000000000000000000000000000000000000000000";
let contract = project.flatten(&root.join("UniswapExchange.sol")).expect("failed to flatten contract");

let client = Client::new_from_env(Chain::Mainnet).unwrap();

let contract =
VerifyContract::new(address, contract.to_string(), compiler_version.to_string())
VerifyContract::new(address, contract, compiler_version.to_string())
.constructor_arguments(Some(constructor_args))
.optimization(true)
.runs(200);

let _resp = client.submit_contract_verification(&contract).await;
}).await
})
.await
}
}

0 comments on commit d39c024

Please sign in to comment.