From 5752aa0260f47b4b3ec2c5c67ad4aac9fa4a12a4 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Sat, 25 Mar 2023 02:51:33 +0100 Subject: [PATCH] fix mergings --- .../ethers-contract-derive/src/eip712.rs | 59 ++--- .../ethers-contract-derive/src/utils.rs | 7 +- ethers-contract/tests/it/contract.rs | 43 ++-- ethers-contract/tests/it/main.rs | 4 +- .../solidity-contracts/DeriveEip712Test.json | 1 + .../solidity-contracts}/DeriveEip712Test.sol | 1 + .../solidity-contracts/derive_eip712_abi.json | 206 ------------------ ethers/tests/eip712.rs | 158 -------------- ethers/tests/main.rs | 4 - 9 files changed, 58 insertions(+), 425 deletions(-) create mode 100644 ethers-contract/tests/solidity-contracts/DeriveEip712Test.json rename {ethers/tests => ethers-contract/tests/solidity-contracts}/DeriveEip712Test.sol (97%) delete mode 100644 ethers-contract/tests/solidity-contracts/derive_eip712_abi.json delete mode 100644 ethers/tests/eip712.rs delete mode 100644 ethers/tests/main.rs diff --git a/ethers-contract/ethers-contract-derive/src/eip712.rs b/ethers-contract/ethers-contract-derive/src/eip712.rs index 2f91af92..ece0524e 100644 --- a/ethers-contract/ethers-contract-derive/src/eip712.rs +++ b/ethers-contract/ethers-contract-derive/src/eip712.rs @@ -6,7 +6,7 @@ use ethers_core::{ utils::keccak256, }; use inflector::Inflector; -use proc_macro2::TokenStream; +use proc_macro2::{Literal, TokenStream}; use quote::quote; use syn::{spanned::Spanned, Data, DeriveInput, Error, Fields, LitInt, LitStr, Result, Token}; @@ -17,7 +17,7 @@ pub(crate) fn impl_derive_eip712(input: &DeriveInput) -> Result { // Instantiate domain from parsed attributes let domain = parse_attributes(input)?; - let domain_separator = hex::encode(domain.separator()); + let domain_separator = into_tokens(domain.separator()); let domain_str = serde_json::to_string(&domain).unwrap(); @@ -25,43 +25,38 @@ pub(crate) fn impl_derive_eip712(input: &DeriveInput) -> Result { let parsed_fields = parse_fields(input)?; // Compute the type hash for the derived struct using the parsed fields from above. - let type_hash = hex::encode(make_type_hash(primary_type.to_string(), &parsed_fields)); + let type_hash = into_tokens(make_type_hash(primary_type.to_string(), &parsed_fields)); // Use reference to ethers_core instead of directly using the crate itself. let ethers_core = ethers_core_crate(); let tokens = quote! { - impl Eip712 for #primary_type { + impl #ethers_core::types::transaction::eip712::Eip712 for #primary_type { type Error = #ethers_core::types::transaction::eip712::Eip712Error; - fn type_hash() -> Result<[u8; 32], Self::Error> { - use std::convert::TryFrom; - let decoded = #ethers_core::utils::hex::decode(#type_hash)?; - let byte_array: [u8; 32] = <[u8; 32]>::try_from(&decoded[..])?; - Ok(byte_array) + #[inline] + fn type_hash() -> ::core::result::Result<[u8; 32], Self::Error> { + Ok([#(#type_hash),*]) } - // Return the pre-computed domain separator from compile time; - fn domain_separator(&self) -> Result<[u8; 32], Self::Error> { - use std::convert::TryFrom; - let decoded = #ethers_core::utils::hex::decode(#domain_separator)?; - let byte_array: [u8; 32] = <[u8; 32]>::try_from(&decoded[..])?; - Ok(byte_array) + #[inline] + fn domain_separator(&self) -> ::core::result::Result<[u8; 32], Self::Error> { + Ok([#(#domain_separator),*]) } - fn domain(&self) -> Result<#ethers_core::types::transaction::eip712::EIP712Domain, Self::Error> { - let domain: #ethers_core::types::transaction::eip712::EIP712Domain = # ethers_core::utils::__serde_json::from_str(#domain_str)?; - - Ok(domain) + fn domain(&self) -> ::core::result::Result<#ethers_core::types::transaction::eip712::EIP712Domain, Self::Error> { + #ethers_core::utils::__serde_json::from_str(#domain_str).map_err(::core::convert::Into::into) } - fn struct_hash(&self) -> Result<[u8; 32], Self::Error> { - use #ethers_core::abi::Tokenizable; + fn struct_hash(&self) -> ::core::result::Result<[u8; 32], Self::Error> { let mut items = vec![#ethers_core::abi::Token::Uint( #ethers_core::types::U256::from(&Self::type_hash()?[..]), )]; - if let #ethers_core::abi::Token::Tuple(tokens) = self.clone().into_token() { + if let #ethers_core::abi::Token::Tuple(tokens) = + #ethers_core::abi::Tokenizable::into_token(::core::clone::Clone::clone(self)) + { + items.reserve(tokens.len()); for token in tokens { match &token { #ethers_core::abi::Token::Tuple(t) => { @@ -163,10 +158,24 @@ fn parse_fields(input: &DeriveInput) -> Result> { /// Convert hash map of field names and types into a type hash corresponding to enc types; fn make_type_hash(primary_type: String, fields: &[(String, ParamType)]) -> [u8; 32] { - let parameters = - fields.iter().map(|(k, v)| format!("{v} {k}")).collect::>().join(","); + let mut sig = String::with_capacity(256); - let sig = format!("{primary_type}({parameters})"); + sig.push_str(&primary_type); + + sig.push('('); + for (i, (name, ty)) in fields.iter().enumerate() { + sig.push_str(&ty.to_string()); + sig.push(' '); + sig.push_str(name); + if i < fields.len() - 1 { + sig.push(','); + } + } + sig.push(')'); keccak256(sig) } + +fn into_tokens(bytes: [u8; 32]) -> impl Iterator { + bytes.into_iter().map(Literal::u8_suffixed) +} diff --git a/ethers-contract/ethers-contract-derive/src/utils.rs b/ethers-contract/ethers-contract-derive/src/utils.rs index 309a6d4b..dfb49513 100644 --- a/ethers-contract/ethers-contract-derive/src/utils.rs +++ b/ethers-contract/ethers-contract-derive/src/utils.rs @@ -140,8 +140,11 @@ pub fn find_parameter_type(ty: &Type) -> Result { let ty = find_parameter_type(&arr.elem)?; if let Expr::Lit(ref expr) = arr.len { if let Lit::Int(ref len) = expr.lit { - if let Ok(size) = len.base10_parse::() { - return Ok(ParamType::FixedArray(Box::new(ty), size)) + if let Ok(len) = len.base10_parse::() { + return match (ty, len) { + (ParamType::Uint(8), 32) => Ok(ParamType::FixedBytes(32)), + (ty, len) => Ok(ParamType::FixedArray(Box::new(ty), len)), + } } } } diff --git a/ethers-contract/tests/it/contract.rs b/ethers-contract/tests/it/contract.rs index ecce3b24..eb5b0c8b 100644 --- a/ethers-contract/tests/it/contract.rs +++ b/ethers-contract/tests/it/contract.rs @@ -5,7 +5,10 @@ use ethers_contract::{ }; use ethers_core::{ abi::{encode, AbiEncode, Token, Tokenizable}, - types::{Address, BlockId, Bytes, Filter, ValueOrArray, H160, H256, U256}, + types::{ + transaction::eip712::*, Address, BlockId, Bytes, Filter, ValueOrArray, H160, H256, I256, + U256, + }, utils::{keccak256, Anvil}, }; use ethers_providers::{Http, Middleware, MiddlewareError, Provider, StreamExt, Ws}; @@ -787,7 +790,7 @@ async fn test_derive_eip712() { mod contract { ethers_contract::abigen!( DeriveEip712Test, - "./ethers-contract/tests/solidity-contracts/derive_eip712_abi.json", + "./ethers-contract/tests/solidity-contracts/DeriveEip712Test.json", derives(serde::Deserialize, serde::Serialize) ); } @@ -811,33 +814,17 @@ async fn test_derive_eip712() { out: Address, } - // get ABI and bytecode for the DeriveEip712Test contract - let (abi, bytecode) = compile_contract("DeriveEip712Test", "DeriveEip712Test.sol"); - // launch the network & connect to it let anvil = Anvil::new().spawn(); - let from = anvil.addresses()[0]; + let wallet: LocalWallet = anvil.keys()[0].clone().into(); let provider = Provider::try_from(anvil.endpoint()) .unwrap() - .with_sender(from) + .with_sender(wallet.address()) .interval(std::time::Duration::from_millis(10)); let client = Arc::new(provider); - let wallet: LocalWallet = anvil.keys()[0].clone().into(); - - let factory = ContractFactory::new(abi.clone(), bytecode.clone(), client.clone()); - - let contract = factory - .deploy(()) - .expect("failed to deploy DeriveEip712Test contract") - .legacy() - .send() - .await - .expect("failed to instantiate factory for DeriveEip712 contract"); - - let addr = contract.address(); - - let contract = contract::DeriveEip712Test::new(addr, client.clone()); + let contract: contract::DeriveEip712Test<_> = + contract::DeriveEip712Test::deploy(client.clone(), ()).unwrap().send().await.unwrap(); let foo_bar = FooBar { foo: I256::from(10u64), @@ -845,7 +832,7 @@ async fn test_derive_eip712() { fizz: b"fizz".into(), buzz: keccak256("buzz"), far: String::from("space"), - out: Address::from([0; 20]), + out: Address::zero(), }; let derived_foo_bar = contract::FooBar { @@ -859,11 +846,11 @@ async fn test_derive_eip712() { let sig = wallet.sign_typed_data(&foo_bar).await.expect("failed to sign typed data"); - let r = <[u8; 32]>::try_from(sig.r) - .expect("failed to parse 'r' value from signature into [u8; 32]"); - let s = <[u8; 32]>::try_from(sig.s) - .expect("failed to parse 's' value from signature into [u8; 32]"); - let v = u8::try_from(sig.v).expect("failed to parse 'v' value from signature into u8"); + let mut r = [0; 32]; + sig.r.to_big_endian(&mut r); + let mut s = [0; 32]; + sig.s.to_big_endian(&mut s); + let v = sig.v as u8; let domain_separator = contract .domain_separator() diff --git a/ethers-contract/tests/it/main.rs b/ethers-contract/tests/it/main.rs index 9e1f2888..d8a65070 100644 --- a/ethers-contract/tests/it/main.rs +++ b/ethers-contract/tests/it/main.rs @@ -9,8 +9,8 @@ mod contract_call; mod eip712; -#[cfg(all(not(target_arch = "wasm32"), not(feature = "celo")))] +// #[cfg(all(not(target_arch = "wasm32"), not(feature = "celo")))] mod common; -#[cfg(all(not(target_arch = "wasm32"), not(feature = "celo")))] +// #[cfg(all(not(target_arch = "wasm32"), not(feature = "celo")))] mod contract; diff --git a/ethers-contract/tests/solidity-contracts/DeriveEip712Test.json b/ethers-contract/tests/solidity-contracts/DeriveEip712Test.json new file mode 100644 index 00000000..c9865358 --- /dev/null +++ b/ethers-contract/tests/solidity-contracts/DeriveEip712Test.json @@ -0,0 +1 @@ +{"abi":[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"domainSeparator","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"int256","name":"foo","type":"int256"},{"internalType":"uint256","name":"bar","type":"uint256"},{"internalType":"bytes","name":"fizz","type":"bytes"},{"internalType":"bytes32","name":"buzz","type":"bytes32"},{"internalType":"string","name":"far","type":"string"},{"internalType":"address","name":"out","type":"address"}],"internalType":"struct DeriveEip712Test.FooBar","name":"fooBar","type":"tuple"}],"name":"encodeEip712","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"int256","name":"foo","type":"int256"},{"internalType":"uint256","name":"bar","type":"uint256"},{"internalType":"bytes","name":"fizz","type":"bytes"},{"internalType":"bytes32","name":"buzz","type":"bytes32"},{"internalType":"string","name":"far","type":"string"},{"internalType":"address","name":"out","type":"address"}],"internalType":"struct DeriveEip712Test.FooBar","name":"fooBar","type":"tuple"}],"name":"structHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[],"name":"typeHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"signer","type":"address"},{"components":[{"internalType":"int256","name":"foo","type":"int256"},{"internalType":"uint256","name":"bar","type":"uint256"},{"internalType":"bytes","name":"fizz","type":"bytes"},{"internalType":"bytes32","name":"buzz","type":"bytes32"},{"internalType":"string","name":"far","type":"string"},{"internalType":"address","name":"out","type":"address"}],"internalType":"struct DeriveEip712Test.FooBar","name":"fooBar","type":"tuple"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"uint8","name":"v","type":"uint8"}],"name":"verifyFooBar","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}],"bytecode":{"object":"0x608060405234801561001057600080fd5b50610588806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80630e81d1ea1461005c5780631a82ff96146100825780634992602814610095578063d8ef409b146100bb578063f698da25146100de575b600080fd5b61006f61006a366004610499565b6100e6565b6040519081526020015b60405180910390f35b61006f610090366004610499565b610135565b7f444a4f3bd4b9709dad515de69ec13a80dfaf37cdaff8705e0b7ad3b050f8a05d61006f565b6100ce6100c93660046104d6565b6101c2565b6040519015158152602001610079565b61006f610246565b60006100f0610246565b6100f983610135565b60405161190160f01b6020820152602281019290925260428201526062015b604051602081830303815290604052805190602001209050919050565b60007f444a4f3bd4b9709dad515de69ec13a80dfaf37cdaff8705e0b7ad3b050f8a05d82516020808501516040808701518051908401206060808901516080808b015180519088012060a0808d01518751998a019b909b52958801989098529186019490945284015282015260c08101919091526001600160a01b0390911660e082015261010001610118565b600060016101cf866100e6565b6040805160008152602081018083529290925260ff851690820152606081018690526080810185905260a0016020604051602081039080840390855afa15801561021d573d6000803e3d6000fd5b505050602060405103516001600160a01b0316866001600160a01b031614905095945050505050565b604080517fd87cd6ef79d4e2b95e15ce8abf732db51ec771f1ca2edccf22a46c729ac5647260208201527f980de4e67a47e184738cefeb37eafc9ae849b00443ea6d49487ca4488633f4fd918101919091527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260016080820181905260a08201527f6f6f42aa4c3c5871ad1af387553372290fd350e98f6d38559f840f21b79da02e60c082015260009060e00160405160208183030381529060405280519060200120905090565b634e487b7160e01b600052604160045260246000fd5b60405160c0810167ffffffffffffffff8111828210171561034c5761034c610313565b60405290565b600082601f83011261036357600080fd5b813567ffffffffffffffff8082111561037e5761037e610313565b604051601f8301601f19908116603f011681019082821181831017156103a6576103a6610313565b816040528381528660208588010111156103bf57600080fd5b836020870160208301376000602085830101528094505050505092915050565b80356001600160a01b03811681146103f657600080fd5b919050565b600060c0828403121561040d57600080fd5b610415610329565b90508135815260208201356020820152604082013567ffffffffffffffff8082111561044057600080fd5b61044c85838601610352565b604084015260608401356060840152608084013591508082111561046f57600080fd5b5061047c84828501610352565b60808301525061048e60a083016103df565b60a082015292915050565b6000602082840312156104ab57600080fd5b813567ffffffffffffffff8111156104c257600080fd5b6104ce848285016103fb565b949350505050565b600080600080600060a086880312156104ee57600080fd5b6104f7866103df565b9450602086013567ffffffffffffffff81111561051357600080fd5b61051f888289016103fb565b9450506040860135925060608601359150608086013560ff8116811461054457600080fd5b80915050929550929590935056fea2646970667358221220cf29bf472d8a14fac807f7e952af4f1e27c3ec66e38093f54930dfc99f473b3264736f6c63430008130033","sourceMap":"101:2177:0:-:0;;;737:23;;;;;;;;;;101:2177;;;;;;","linkReferences":{}}} diff --git a/ethers/tests/DeriveEip712Test.sol b/ethers-contract/tests/solidity-contracts/DeriveEip712Test.sol similarity index 97% rename from ethers/tests/DeriveEip712Test.sol rename to ethers-contract/tests/solidity-contracts/DeriveEip712Test.sol index 0aced88b..311c8e38 100644 --- a/ethers/tests/DeriveEip712Test.sol +++ b/ethers-contract/tests/solidity-contracts/DeriveEip712Test.sol @@ -2,6 +2,7 @@ pragma solidity >=0.6.0; pragma experimental ABIEncoderV2; +// note that this file is not synced with DeriveEip712Test.json contract DeriveEip712Test { uint256 constant chainId = 1; bytes32 constant salt = keccak256("eip712-test-75F0CCte"); diff --git a/ethers-contract/tests/solidity-contracts/derive_eip712_abi.json b/ethers-contract/tests/solidity-contracts/derive_eip712_abi.json deleted file mode 100644 index a978024e..00000000 --- a/ethers-contract/tests/solidity-contracts/derive_eip712_abi.json +++ /dev/null @@ -1,206 +0,0 @@ -[ - { - "inputs": [], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "inputs": [], - "name": "domainSeparator", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "int256", - "name": "foo", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "bar", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "fizz", - "type": "bytes" - }, - { - "internalType": "bytes32", - "name": "buzz", - "type": "bytes32" - }, - { - "internalType": "string", - "name": "far", - "type": "string" - }, - { - "internalType": "address", - "name": "out", - "type": "address" - } - ], - "internalType": "struct DeriveEip712Test.FooBar", - "name": "fooBar", - "type": "tuple" - } - ], - "name": "encodeEip712", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "int256", - "name": "foo", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "bar", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "fizz", - "type": "bytes" - }, - { - "internalType": "bytes32", - "name": "buzz", - "type": "bytes32" - }, - { - "internalType": "string", - "name": "far", - "type": "string" - }, - { - "internalType": "address", - "name": "out", - "type": "address" - } - ], - "internalType": "struct DeriveEip712Test.FooBar", - "name": "fooBar", - "type": "tuple" - } - ], - "name": "structHash", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [], - "name": "typeHash", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "signer", - "type": "address" - }, - { - "components": [ - { - "internalType": "int256", - "name": "foo", - "type": "int256" - }, - { - "internalType": "uint256", - "name": "bar", - "type": "uint256" - }, - { - "internalType": "bytes", - "name": "fizz", - "type": "bytes" - }, - { - "internalType": "bytes32", - "name": "buzz", - "type": "bytes32" - }, - { - "internalType": "string", - "name": "far", - "type": "string" - }, - { - "internalType": "address", - "name": "out", - "type": "address" - } - ], - "internalType": "struct DeriveEip712Test.FooBar", - "name": "fooBar", - "type": "tuple" - }, - { - "internalType": "bytes32", - "name": "r", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "s", - "type": "bytes32" - }, - { - "internalType": "uint8", - "name": "v", - "type": "uint8" - } - ], - "name": "verifyFooBar", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "pure", - "type": "function" - } -] \ No newline at end of file diff --git a/ethers/tests/eip712.rs b/ethers/tests/eip712.rs deleted file mode 100644 index 869bb635..00000000 --- a/ethers/tests/eip712.rs +++ /dev/null @@ -1,158 +0,0 @@ -use ethers::{ - contract::{abigen, ContractFactory, Eip712, EthAbiType}, - core::{ - types::{transaction::eip712::Eip712, Address, Bytes, I256, U256}, - utils::{keccak256, Anvil}, - }, - providers::Provider, - signers::LocalWallet, - solc::Solc, -}; -use std::{path::PathBuf, sync::Arc}; - -#[tokio::test(flavor = "multi_thread")] -async fn test_derive_eip712() { - // Generate Contract ABI Bindings - abigen!( - DeriveEip712Test, - "./ethers-contract/tests/solidity-contracts/derive_eip712_abi.json", - event_derives(serde::Deserialize, serde::Serialize) - ); - - // Create derived structs - - #[derive(Debug, Clone, Eip712, EthAbiType)] - #[eip712( - name = "Eip712Test", - version = "1", - chain_id = 1, - verifying_contract = "0x0000000000000000000000000000000000000001", - salt = "eip712-test-75F0CCte" - )] - struct FooBar { - foo: I256, - bar: U256, - fizz: Bytes, - buzz: [u8; 32], - far: String, - out: Address, - } - - // get ABI and bytecode for the DeriveEip712Test contract - let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests"); - Solc::find_or_install_svm_version("0.6.0").unwrap(); // install solc - let result = Solc::default().compile_source(path).unwrap(); - let (abi, bytecode, _) = result - .find("DeriveEip712Test") - .expect("failed to get DeriveEip712Test contract") - .into_parts_or_default(); - - // launch the network & connect to it - let anvil = Anvil::new().spawn(); - let from = anvil.addresses()[0]; - let provider = Provider::try_from(anvil.endpoint()) - .unwrap() - .with_sender(from) - .interval(std::time::Duration::from_millis(10)); - let client = Arc::new(provider); - - let factory = ContractFactory::new(abi.clone(), bytecode.clone(), client.clone()); - - let contract = factory - .deploy(()) - .expect("failed to deploy DeriveEip712Test contract") - .legacy() - .send() - .await - .expect("failed to instantiate factory for DeriveEip712 contract"); - - let addr = contract.address(); - - let contract = DeriveEip712Test::new(addr, client.clone()); - - let foo_bar = FooBar { - foo: I256::from(10u64), - bar: U256::from(20u64), - fizz: b"fizz".into(), - buzz: keccak256("buzz"), - far: String::from("space"), - out: Address::from([0; 20]), - }; - - let derived_foo_bar = derive_eip_712_test::FooBar { - foo: foo_bar.foo, - bar: foo_bar.bar, - fizz: foo_bar.fizz.clone(), - buzz: foo_bar.buzz, - far: foo_bar.far.clone(), - out: foo_bar.out, - }; - - use ethers::signers::Signer; - - let wallet: LocalWallet = anvil.keys()[0].clone().into(); - let sig = wallet.sign_typed_data(&foo_bar).await.expect("failed to sign typed data"); - - let r = <[u8; 32]>::try_from(sig.r) - .expect("failed to parse 'r' value from signature into [u8; 32]"); - let s = <[u8; 32]>::try_from(sig.s) - .expect("failed to parse 's' value from signature into [u8; 32]"); - let v = u8::try_from(sig.v).expect("failed to parse 'v' value from signature into u8"); - - let domain_separator = contract - .domain_separator() - .call() - .await - .expect("failed to retrieve domain_separator from contract"); - let type_hash = - contract.type_hash().call().await.expect("failed to retrieve type_hash from contract"); - let struct_hash = contract - .struct_hash(derived_foo_bar.clone()) - .call() - .await - .expect("failed to retrieve struct_hash from contract"); - let encoded = contract - .encode_eip_712(derived_foo_bar.clone()) - .call() - .await - .expect("failed to retrieve eip712 encoded hash from contract"); - let verify = contract - .verify_foo_bar(wallet.address(), derived_foo_bar, r, s, v) - .call() - .await - .expect("failed to verify signed typed data eip712 payload"); - - assert_eq!( - domain_separator, - foo_bar - .domain() - .expect("failed to return domain_separator from Eip712 implemented struct") - .separator(), - "domain separator does not match contract domain separator!" - ); - - assert_eq!( - type_hash, - FooBar::type_hash().expect("failed to return type_hash from Eip712 implemented struct"), - "type hash does not match contract struct type hash!" - ); - - assert_eq!( - struct_hash, - foo_bar - .clone() - .struct_hash() - .expect("failed to return struct_hash from Eip712 implemented struct"), - "struct hash does not match contract struct hash!" - ); - - assert_eq!( - encoded, - foo_bar - .encode_eip712() - .expect("failed to return domain_separator from Eip712 implemented struct"), - "Encoded value does not match!" - ); - - assert!(verify, "typed data signature failed!"); -} diff --git a/ethers/tests/main.rs b/ethers/tests/main.rs deleted file mode 100644 index d4845162..00000000 --- a/ethers/tests/main.rs +++ /dev/null @@ -1,4 +0,0 @@ -//! Ethers integration tests. -#![cfg(not(target_arch = "wasm32"))] - -mod eip712;