-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: `sol!` contracts * chore: clippy * docs: add note about parser design, leniency * test: bless tests after updating to syn 2.0.19 * typo * test: bless new test
- Loading branch information
Showing
19 changed files
with
829 additions
and
130 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use syn::Attribute; | ||
|
||
pub(crate) fn docs(attrs: &[Attribute]) -> impl Iterator<Item = &Attribute> { | ||
attrs.iter().filter(|attr| attr.path().is_ident("doc")) | ||
} | ||
|
||
pub(crate) fn derives(attrs: &[Attribute]) -> impl Iterator<Item = &Attribute> { | ||
attrs.iter().filter(|attr| attr.path().is_ident("derive")) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,42 @@ | ||
use alloy_primitives::{Address, U256}; | ||
use alloy_sol_types::{sol, SolCall}; | ||
use hex_literal::hex; | ||
|
||
sol! { | ||
/// Interface of the ERC20 standard as defined in [the EIP]. | ||
/// | ||
/// [the EIP]: https://eips.ethereum.org/EIPS/eip-20 | ||
#[derive(Debug, PartialEq)] | ||
interface IERC20 { | ||
// TODO: Events | ||
// event Transfer(address indexed from, address indexed to, uint256 value); | ||
// event Approval(address indexed owner, address indexed spender, uint256 value); | ||
|
||
function totalSupply() external view returns (uint256); | ||
function balanceOf(address account) external view returns (uint256); | ||
function transfer(address to, uint256 amount) external returns (bool); | ||
function allowance(address owner, address spender) external view returns (uint256); | ||
function approve(address spender, uint256 amount) external returns (bool); | ||
function transferFrom(address from, address to, uint256 amount) external returns (bool); | ||
} | ||
} | ||
|
||
#[test] | ||
fn contracts() { | ||
// TODO | ||
// random mainnet ERC20 transfer | ||
// https://etherscan.io/tx/0x947332ff624b5092fb92e8f02cdbb8a50314e861a4b39c29a286b3b75432165e | ||
let data = hex!( | ||
"a9059cbb" | ||
"0000000000000000000000008bc47be1e3abbaba182069c89d08a61fa6c2b292" | ||
"0000000000000000000000000000000000000000000000000000000253c51700" | ||
); | ||
let expected = IERC20::transferCall { | ||
to: Address::from(hex!("8bc47be1e3abbaba182069c89d08a61fa6c2b292")), | ||
amount: U256::from(9995360000_u64), | ||
}; | ||
|
||
assert_eq!(data[..4], IERC20::transferCall::SELECTOR); | ||
let decoded = IERC20::IERC20Calls::decode(&data, true).unwrap(); | ||
assert_eq!(decoded, IERC20::IERC20Calls::transfer(expected)); | ||
assert_eq!(decoded.encode(), data); | ||
} |
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,21 @@ | ||
use alloy_sol_types::sol; | ||
|
||
sol! { | ||
contract C { | ||
contract Nested {} | ||
} | ||
} | ||
|
||
sol! { | ||
interface C { | ||
library Nested {} | ||
} | ||
} | ||
|
||
sol! { | ||
abstract contract C { | ||
interface Nested {} | ||
} | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.