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

Commit

Permalink
test: add underscore test
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Oct 14, 2021
1 parent cb46b1a commit 9fb26d5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
25 changes: 24 additions & 1 deletion ethers-contract/tests/abigen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Test cases to validate the `abigen!` macro
use ethers_contract::{abigen, EthEvent};
use ethers_core::abi::{Address, Tokenizable};
use ethers_core::types::U256;
use ethers_core::types::{H256, U256};
use ethers_providers::Provider;
use std::sync::Arc;

Expand Down Expand Up @@ -193,3 +193,26 @@ fn can_handle_overloaded_functions() {
let _ = contract.get_value_with_other_value(1337u64.into());
let _ = contract.get_value_with_other_value_and_addr(1337u64.into(), Address::zero());
}

#[test]
fn can_handle_underscore_functions() {
abigen!(
MyContract,
r#"[
_hashPuzzle() (uint256)
]"#
);
abigen!(
SimpleStorage,
"ethers-contract/tests/solidity-contracts/simplestorage_abi.json",
);

let (provider, _) = Provider::mocked();
let client = Arc::new(provider);
let contract = MyContract::new(Address::zero(), client.clone());
// ensure both functions are callable
let _ = contract.hash_puzzle();
let _fun = contract.method::<_, H256>("_hashPuzzle", ()).unwrap();
let contract = SimpleStorage::new(Address::zero(), client);
let _fun = contract.method::<_, H256>("_hashPuzzle", ()).unwrap();
}
2 changes: 2 additions & 0 deletions ethers-contract/tests/solidity-contracts/SimpleStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ contract SimpleStorage {
_otherValue = value2;
lastSender = msg.sender;
}

function _hashPuzzle() public {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"string","name":"value","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"author","type":"address"},{"indexed":true,"internalType":"address","name":"oldAuthor","type":"address"},{"indexed":false,"internalType":"string","name":"oldValue","type":"string"},{"indexed":false,"internalType":"string","name":"newValue","type":"string"}],"name":"ValueChanged","type":"event"},{"inputs":[],"name":"_hashPuzzle","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getValue","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastSender","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"value","type":"string"}],"name":"setValue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"value","type":"string"},{"internalType":"string","name":"value2","type":"string"}],"name":"setValues","outputs":[],"stateMutability":"nonpayable","type":"function"}]

0 comments on commit 9fb26d5

Please sign in to comment.