-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: restructure tests * names * names2
- Loading branch information
Showing
17 changed files
with
275 additions
and
274 deletions.
There are no files selected for viewing
2 changes: 0 additions & 2 deletions
2
crates/json-abi/tests/abi_item_test.rs → crates/json-abi/tests/it/abi_items.rs
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
mod test_helpers; | ||
|
||
use alloy_json_abi::{ | ||
AbiItem, Event, EventParam, Function, | ||
InternalType::{Other, Struct}, | ||
|
2 changes: 0 additions & 2 deletions
2
crates/json-abi/tests/json_abi_test.rs → crates/json-abi/tests/it/abis.rs
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
2 changes: 0 additions & 2 deletions
2
crates/json-abi/tests/event_param_test.rs → crates/json-abi/tests/it/event_params.rs
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
mod test_helpers; | ||
|
||
use alloy_json_abi::{EventParam, Param}; | ||
|
||
#[test] | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#[macro_use] | ||
mod macros; | ||
|
||
mod abi_items; | ||
mod abis; | ||
mod event_params; | ||
mod params; | ||
mod state_mutability; | ||
mod test; |
2 changes: 0 additions & 2 deletions
2
crates/json-abi/tests/param_tests.rs → crates/json-abi/tests/it/params.rs
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
mod test_helpers; | ||
|
||
use alloy_json_abi::{InternalType::Struct, Param}; | ||
|
||
#[test] | ||
|
2 changes: 0 additions & 2 deletions
2
...s/json-abi/tests/state_mutability_test.rs → crates/json-abi/tests/it/state_mutability.rs
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
mod test_helpers; | ||
|
||
use alloy_json_abi::StateMutability; | ||
|
||
#[test] | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod sol; | ||
mod udvt; |
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,65 @@ | ||
use alloy_primitives::B256; | ||
use alloy_sol_types::{eip712_domain, sol, SolStruct}; | ||
|
||
#[test] | ||
fn encode_type_nesting() { | ||
sol! { | ||
struct A { | ||
uint256 a; | ||
} | ||
|
||
struct B { | ||
bytes32 b; | ||
} | ||
|
||
struct C { | ||
A a; | ||
B b; | ||
} | ||
|
||
struct D { | ||
C c; | ||
A a; | ||
B b; | ||
} | ||
} | ||
|
||
assert_eq!(A::eip712_encode_type(), "A(uint256 a)"); | ||
assert_eq!(B::eip712_encode_type(), "B(bytes32 b)"); | ||
assert_eq!(C::eip712_encode_type(), "C(A a,B b)A(uint256 a)B(bytes32 b)"); | ||
assert_eq!(D::eip712_encode_type(), "D(C c,A a,B b)A(uint256 a)B(bytes32 b)C(A a,B b)"); | ||
} | ||
|
||
#[test] | ||
fn encode_data_nesting() { | ||
sol! { | ||
struct Person { | ||
string name; | ||
address wallet; | ||
} | ||
|
||
struct Mail { | ||
Person from; | ||
Person to; | ||
string contents; | ||
} | ||
} | ||
let domain = eip712_domain! {}; | ||
|
||
let mail = Mail { | ||
from: Person { | ||
name: "Cow".to_owned(), | ||
wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826".parse().unwrap(), | ||
}, | ||
to: Person { | ||
name: "Bob".to_owned(), | ||
wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB".parse().unwrap(), | ||
}, | ||
contents: "Hello, Bob!".to_owned(), | ||
}; | ||
|
||
assert_eq!( | ||
alloy_sol_types::SolStruct::eip712_signing_hash(&mail, &domain), | ||
"25c3d40a39e639a4d0b6e4d2ace5e1281e039c88494d97d8d08f99a6ea75d775".parse::<B256>().unwrap() | ||
) | ||
} |
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,116 @@ | ||
use alloy_primitives::{Address, U256}; | ||
use alloy_sol_types::{sol, SolCall, SolError, SolStruct}; | ||
use std::borrow::Cow; | ||
|
||
#[test] | ||
fn large_array() { | ||
sol!(LargeArray, "../json-abi/tests/abi/LargeArray.json"); | ||
assert_eq!(LargeArray::callWithLongArrayCall::SIGNATURE, "callWithLongArray(uint64[128])"); | ||
} | ||
|
||
#[test] | ||
fn seaport() { | ||
sol!(Seaport, "../json-abi/tests/abi/Seaport.json"); | ||
use Seaport::*; | ||
|
||
// BasicOrderType is a uint8 UDVT | ||
let _ = BasicOrderType::from(0u8); | ||
|
||
// BasicOrderParameters is a struct that contains UDVTs (basicOrderType) and a | ||
// struct array. The only component should be the struct of the struct array. | ||
let root_type = "BasicOrderParameters(address considerationToken,uint256 considerationIdentifier,uint256 considerationAmount,address offerer,address zone,address offerToken,uint256 offerIdentifier,uint256 offerAmount,uint8 basicOrderType,uint256 startTime,uint256 endTime,bytes32 zoneHash,uint256 salt,bytes32 offererConduitKey,bytes32 fulfillerConduitKey,uint256 totalOriginalAdditionalRecipients,AdditionalRecipient[] additionalRecipients,bytes signature)"; | ||
let component = "AdditionalRecipient(uint256 amount,address recipient)"; | ||
|
||
assert_eq!(BasicOrderParameters::eip712_root_type(), root_type); | ||
assert_eq!(BasicOrderParameters::eip712_components(), [Cow::Borrowed(component)]); | ||
assert_eq!( | ||
<BasicOrderParameters as SolStruct>::eip712_encode_type(), | ||
root_type.to_string() + component | ||
); | ||
} | ||
|
||
// Handle multiple identical error objects in the JSON ABI | ||
// https://github.com/alloy-rs/core/issues/344 | ||
#[test] | ||
fn aggregation_router_v5() { | ||
sol!(AggregationRouterV5, "../json-abi/tests/abi/AggregationRouterV5.json"); | ||
|
||
assert_eq!( | ||
<AggregationRouterV5::ETHTransferFailed as SolError>::SIGNATURE, | ||
"ETHTransferFailed()" | ||
); | ||
assert_eq!(<AggregationRouterV5::InvalidMsgValue as SolError>::SIGNATURE, "InvalidMsgValue()"); | ||
} | ||
|
||
// Handle contract types in JSON ABI | ||
// https://github.com/alloy-rs/core/issues/351 | ||
#[test] | ||
fn uniswap_v3_position() { | ||
sol!(UniswapV3Position, "../json-abi/tests/abi/UniswapV3Position.json"); | ||
|
||
let _ = UniswapV3Position::getLiquidityByRangeCall { | ||
pool_: Address::ZERO, | ||
self_: Address::ZERO, | ||
lowerTick_: 0, | ||
upperTick_: 0, | ||
}; | ||
assert_eq!( | ||
UniswapV3Position::getLiquidityByRangeCall::SIGNATURE, | ||
"getLiquidityByRange(address,address,int24,int24)" | ||
); | ||
|
||
let _ = | ||
UniswapV3Position::getPositionIdCall { self_: Address::ZERO, lowerTick_: 0, upperTick_: 0 }; | ||
assert_eq!( | ||
UniswapV3Position::getPositionIdCall::SIGNATURE, | ||
"getPositionId(address,int24,int24)" | ||
); | ||
} | ||
|
||
// Ensure a trailing comma for single-element tuples in old JSON ABI | ||
// https://github.com/alloy-rs/core/issues/360 | ||
#[test] | ||
fn double_exponent_interest_setter() { | ||
sol!(DoubleExponentInterestSetter, "../json-abi/tests/abi/DoubleExponentInterestSetter.json"); | ||
let _ = DoubleExponentInterestSetter::getInterestRateCall { | ||
_0: Address::ZERO, | ||
borrowWei: U256::ZERO, | ||
supplyWei: U256::ZERO, | ||
}; | ||
} | ||
|
||
// Same as `event_tokenize_fields` | ||
// https://github.com/alloy-rs/core/issues/361 | ||
#[test] | ||
fn uniswap_v2_factory() { | ||
sol!(UniswapV2Factory, "../json-abi/tests/abi/UniswapV2Factory.json"); | ||
let _ = UniswapV2Factory::PairCreated { | ||
token0: Address::ZERO, | ||
token1: Address::ZERO, | ||
pair: Address::ZERO, | ||
_3: U256::ZERO, | ||
}; | ||
} | ||
|
||
// Fully qualify `SolInterface::NAME` which conflicted with the `NAME` call | ||
// https://github.com/alloy-rs/core/issues/361 | ||
#[test] | ||
fn gnosis_safe() { | ||
sol!(GnosisSafe, "../json-abi/tests/abi/GnosisSafe.json"); | ||
let GnosisSafe::NAMECall {} = GnosisSafe::NAMECall {}; | ||
let GnosisSafe::NAMEReturn { _0: _ } = GnosisSafe::NAMEReturn { _0: String::new() }; | ||
} | ||
|
||
// Have enough recursion depth to handle `BlurExchange` types | ||
// https://github.com/alloy-rs/core/issues/371 | ||
#[test] | ||
fn blur_exchange() { | ||
sol!(BlurExchange, "../json-abi/tests/abi/BlurExchange.json"); | ||
let BlurExchange::NAMECall {} = BlurExchange::NAMECall {}; | ||
let BlurExchange::NAMEReturn { _0: _ } = BlurExchange::NAMEReturn { _0: String::new() }; | ||
} | ||
|
||
#[test] | ||
fn zerox_proxy() { | ||
sol!(ZeroXExchangeProxy, "../json-abi/tests/abi/ZeroxExchangeProxy.json"); | ||
} |
Oops, something went wrong.