Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removing failed test containers #211

Merged
merged 12 commits into from
Jan 19, 2024
132 changes: 70 additions & 62 deletions chains/astar/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ mod tests {
use alloy_sol_types::{sol, SolCall};
use ethers_solc::{artifacts::Source, CompilerInput, EvmVersion, Solc};
use rosetta_config_ethereum::{AtBlock, CallResult};
use rosetta_docker::Env;
use rosetta_docker::{run_test, Env};
use sha3::Digest;
use std::{collections::BTreeMap, path::Path};

Expand Down Expand Up @@ -305,74 +305,82 @@ mod tests {
let config = rosetta_config_astar::config("dev")?;

let env = Env::new("astar-smart-contract", config.clone(), client_from_config).await?;

let faucet = 100 * u128::pow(10, config.currency_decimals);
let wallet = env.ephemeral_wallet().await?;
wallet.faucet(faucet).await?;

let bytes = compile_snippet(
r"
event AnEvent();
function emitEvent() public {
emit AnEvent();
}
",
)?;
let tx_hash = wallet.eth_deploy_contract(bytes).await?;
let receipt = wallet.eth_transaction_receipt(tx_hash).await?.unwrap();
let contract_address = receipt.contract_address.unwrap();
let tx_hash = {
let data = TestContract::emitEventCall::SELECTOR.to_vec();
wallet.eth_send_call(contract_address.0, data, 0).await?
};
let receipt = wallet.eth_transaction_receipt(tx_hash).await?.unwrap();
let logs = receipt.logs;
assert_eq!(logs.len(), 1);
let topic = logs[0].topics[0];
let expected = H256::from_slice(sha3::Keccak256::digest("AnEvent()").as_ref());
assert_eq!(topic, expected);
env.shutdown().await?;
run_test(env, |env| async move {
let faucet = 100 * u128::pow(10, config.currency_decimals);
let wallet = env.ephemeral_wallet().await.unwrap();
wallet.faucet(faucet).await.unwrap();

let bytes = compile_snippet(
r"
event AnEvent();
function emitEvent() public {
emit AnEvent();
}
",
)
.unwrap();
let tx_hash = wallet.eth_deploy_contract(bytes).await.unwrap();
let receipt = wallet.eth_transaction_receipt(tx_hash).await.unwrap().unwrap();
let contract_address = receipt.contract_address.unwrap();
let tx_hash = {
let data = TestContract::emitEventCall::SELECTOR.to_vec();
wallet.eth_send_call(contract_address.0, data, 0).await.unwrap()
};
let receipt = wallet.eth_transaction_receipt(tx_hash).await.unwrap().unwrap();
let logs = receipt.logs;
assert_eq!(logs.len(), 1);
let topic = logs[0].topics[0];
let expected = H256::from_slice(sha3::Keccak256::digest("AnEvent()").as_ref());
assert_eq!(topic, expected);
Ok(())
})
.await;
Ok(())
}

#[tokio::test]
async fn test_smart_contract_view() -> Result<()> {
let config = rosetta_config_astar::config("dev")?;
let faucet = 100 * u128::pow(10, config.currency_decimals);

let env = Env::new("astar-smart-contract-view", config, client_from_config).await?;

let wallet = env.ephemeral_wallet().await?;
wallet.faucet(faucet).await?;

let bytes = compile_snippet(
r"
function identity(bool a) public view returns (bool) {
return a;
}
",
)?;
let tx_hash = wallet.eth_deploy_contract(bytes).await?;
let receipt = wallet.eth_transaction_receipt(tx_hash).await?.unwrap();
let contract_address = receipt.contract_address.unwrap();

let response = {
let call = TestContract::identityCall { a: true };
wallet
.eth_view_call(contract_address.0, call.abi_encode(), AtBlock::Latest)
.await?
};
assert_eq!(
response,
CallResult::Success(
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1
]
.to_vec()

let env = Env::new("astar-smart-contract-view", config.clone(), client_from_config).await?;

run_test(env, |env| async move {
let faucet = 100 * u128::pow(10, config.currency_decimals);
let wallet = env.ephemeral_wallet().await.unwrap();
wallet.faucet(faucet).await.unwrap();

let bytes = compile_snippet(
r"
function identity(bool a) public view returns (bool) {
return a;
}
",
)
);
env.shutdown().await?;
.unwrap();
let tx_hash = wallet.eth_deploy_contract(bytes).await.unwrap();
let receipt = wallet.eth_transaction_receipt(tx_hash).await.unwrap().unwrap();
let contract_address = receipt.contract_address.unwrap();

let response = {
let call = TestContract::identityCall { a: true };
wallet
.eth_view_call(contract_address.0, call.abi_encode(), AtBlock::Latest)
.await
.unwrap()
};
assert_eq!(
response,
CallResult::Success(
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1
]
.to_vec()
)
);
Ok(())
})
.await;
Ok(())
}
}
125 changes: 68 additions & 57 deletions chains/ethereum/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ mod tests {
use ethabi::ethereum_types::H256;
use ethers_solc::{artifacts::Source, CompilerInput, EvmVersion, Solc};
use rosetta_config_ethereum::{AtBlock, CallResult};
use rosetta_docker::Env;
use rosetta_docker::{run_test, Env};
use sha3::Digest;
use std::{collections::BTreeMap, path::Path};

Expand Down Expand Up @@ -284,77 +284,88 @@ mod tests {

#[tokio::test]
async fn test_smart_contract() -> Result<()> {
let config = rosetta_config_ethereum::config("dev")?;
let config = rosetta_config_ethereum::config("dev").unwrap();

let env = Env::new("ethereum-smart-contract", config.clone(), client_from_config).await?;

let faucet = 100 * u128::pow(10, config.currency_decimals);
let wallet = env.ephemeral_wallet().await?;
wallet.faucet(faucet).await?;
run_test(env, |env| async move {
let wallet = env.ephemeral_wallet().await.unwrap();

let faucet = 100 * u128::pow(10, config.currency_decimals);
wallet.faucet(faucet).await.unwrap();

let bytes = compile_snippet(
r"
let bytes = compile_snippet(
r"
event AnEvent();
function emitEvent() public {
emit AnEvent();
}
",
)?;
let tx_hash = wallet.eth_deploy_contract(bytes).await?;
let receipt = wallet.eth_transaction_receipt(tx_hash).await?.unwrap();
let contract_address = receipt.contract_address.unwrap();
let tx_hash = {
let call = TestContract::emitEventCall {};
wallet.eth_send_call(contract_address.0, call.abi_encode(), 0).await?
};
let receipt = wallet.eth_transaction_receipt(tx_hash).await?.unwrap();
assert_eq!(receipt.logs.len(), 1);
let topic = receipt.logs[0].topics[0];
let expected = H256(sha3::Keccak256::digest("AnEvent()").into());
assert_eq!(topic, expected);
env.shutdown().await?;
)
.unwrap();
let tx_hash = wallet.eth_deploy_contract(bytes).await.unwrap();
let receipt = wallet.eth_transaction_receipt(tx_hash).await.unwrap().unwrap();
let contract_address = receipt.contract_address.unwrap();
let tx_hash = {
let call = TestContract::emitEventCall {};
wallet.eth_send_call(contract_address.0, call.abi_encode(), 0).await.unwrap()
};
let receipt = wallet.eth_transaction_receipt(tx_hash).await.unwrap().unwrap();
assert_eq!(receipt.logs.len(), 1);
let topic = receipt.logs[0].topics[0];
let expected = H256(sha3::Keccak256::digest("AnEvent()").into());
assert_eq!(topic, expected);
Ok(())
})
.await;
Ok(())
}

#[tokio::test]
async fn test_smart_contract_view() -> Result<()> {
let config = rosetta_config_ethereum::config("dev")?;

let env =
Env::new("ethereum-smart-contract-view", config.clone(), client_from_config).await?;

let faucet = 100 * u128::pow(10, config.currency_decimals);
let wallet = env.ephemeral_wallet().await?;
wallet.faucet(faucet).await?;

let bytes = compile_snippet(
r"
function identity(bool a) public view returns (bool) {
return a;
}
",
)?;
let tx_hash = wallet.eth_deploy_contract(bytes).await?;
let receipt = wallet.eth_transaction_receipt(tx_hash).await?.unwrap();
let contract_address = receipt.contract_address.unwrap();

let response = {
let call = TestContract::identityCall { a: true };
wallet
.eth_view_call(contract_address.0, call.abi_encode(), AtBlock::Latest)
.await?
};
assert_eq!(
response,
CallResult::Success(
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1
]
.to_vec()
let config = rosetta_config_ethereum::config("dev").unwrap();
let env = Env::new("ethereum-smart-contract-view", config.clone(), client_from_config)
.await
.unwrap();

//here is run test function
run_test(env, |env| async move {
let wallet = env.ephemeral_wallet().await.unwrap();
let faucet = 100 * u128::pow(10, config.currency_decimals);
wallet.faucet(faucet).await.unwrap();

let bytes = compile_snippet(
r"
function identity(bool a) public view returns (bool) {
return a;
}
",
)
);
env.shutdown().await?;
.unwrap();
let tx_hash = wallet.eth_deploy_contract(bytes).await.unwrap();
let receipt = wallet.eth_transaction_receipt(tx_hash).await.unwrap().unwrap();
let contract_address = receipt.contract_address.unwrap();

let response = {
let call = TestContract::identityCall { a: true };
wallet
.eth_view_call(contract_address.0, call.abi_encode(), AtBlock::Latest)
.await
.unwrap()
};
assert_eq!(
response,
CallResult::Success(
[
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1
]
.to_vec()
)
);
Ok(())
})
.await;
Ok(())
}
}
Loading
Loading