test(abigen): re-enable tests

This commit is contained in:
Georgios Konstantopoulos 2020-06-10 23:26:37 +03:00
parent aa454b945b
commit 7dbc2d4f25
No known key found for this signature in database
GPG Key ID: FA607837CD26EDBC
3 changed files with 71 additions and 82 deletions

View File

@ -15,7 +15,7 @@ ethers-core = { version = "0.1.0", path = "../ethers-core" }
serde = { version = "1.0.110", default-features = false }
rustc-hex = { version = "2.1.0", default-features = false }
thiserror = { version = "1.0.19", default-features = false }
once_cell = "1.4.0"
once_cell = { version = "1.4.0", default-features = false }
tokio = { version = "0.2.21", default-features = false }
[dev-dependencies]

View File

@ -107,13 +107,13 @@ impl Parse for Parameter {
if !signatures.insert(method.signature.clone()) {
return Err(ParseError::new(
method.span(),
"duplicate method signature in `ethcontract::contract!` macro invocation",
"duplicate method signature in `abigen!` macro invocation",
));
}
if !aliases.insert(method.alias.clone()) {
return Err(ParseError::new(
method.span(),
"duplicate method alias in `ethcontract::contract!` macro invocation",
"duplicate method alias in `abigen!` macro invocation",
));
}
methods.push(method.into_inner())
@ -206,13 +206,13 @@ mod tests {
}};
}
// macro_rules! contract_args {
// ($($arg:tt)*) => {
// contract_args_result!($($arg)*)
// .expect("failed to parse contract args")
// .into_inner()
// };
// }
macro_rules! contract_args {
($($arg:tt)*) => {
contract_args_result!($($arg)*)
.expect("failed to parse contract args")
.into_inner()
};
}
macro_rules! contract_args_err {
($($arg:tt)*) => {
@ -229,77 +229,69 @@ mod tests {
}
}
// #[test]
// fn parse_contract_args() {
// let args = contract_args!("path/to/artifact.json");
// assert_eq!(args.artifact_path, "path/to/artifact.json");
// }
#[test]
fn parse_contract_args() {
let args = contract_args!(TestContract, "path/to/abi.json");
assert_eq!(args.name, "TestContract");
assert_eq!(args.abi, "path/to/abi.json");
}
// #[test]
// fn crate_parameter_accepts_keywords() {
// let args = contract_args!("artifact.json", crate = crate);
// assert_eq!(args.parameters, &[Parameter::Crate("crate".into())]);
// }
#[test]
fn parse_contract_args_with_defaults() {
let args = contract_args!(TestContract, "[{}]");
assert_eq!(
args,
ContractArgs {
name: "TestContract".to_string(),
abi: "[{}]".to_string(),
parameters: vec![],
},
);
}
// TODO: Re-enable these tests once we figure out which syntax we prefer for the macro
// #[test]
// fn parse_contract_args_with_defaults() {
// let args = contract_args!("artifact.json");
// assert_eq!(
// args,
// ContractArgs {
// visibility: None,
// parameters: vec![],
// },
// );
// }
// #[test]
// fn parse_contract_args_with_parameters() {
// let args = contract_args!(
// pub(crate) "artifact.json",
// crate = foobar,
// mod = contract,
// contract = Contract,
// methods {
// myMethod(uint256, bool) as my_renamed_method;
// myOtherMethod() as my_other_renamed_method;
// },
// event_derives (Asdf, a::B, a::b::c::D)
// );
// assert_eq!(
// args,
// ContractArgs {
// visibility: Some(quote!(pub(crate)).to_string()),
// parameters: vec![
// Parameter::Crate("foobar".into()),
// Parameter::Mod("contract".into()),
// // Parameter::Contract("Contract".into()),
// Parameter::Methods(vec![
// method("myMethod(uint256,bool)", "my_renamed_method"),
// method("myOtherMethod()", "my_other_renamed_method"),
// ]),
// Parameter::EventDerives(vec![
// "Asdf".into(),
// "a :: B".into(),
// "a :: b :: c :: D".into()
// ])
// ],
// },
// );
// }
#[test]
fn parse_contract_args_with_parameters() {
let args = contract_args!(
TestContract,
"abi.json",
methods {
myMethod(uint256, bool) as my_renamed_method;
myOtherMethod() as my_other_renamed_method;
},
event_derives (Asdf, a::B, a::b::c::D)
);
assert_eq!(
args,
ContractArgs {
name: "TestContract".to_string(),
abi: "abi.json".to_string(),
parameters: vec![
// Parameter::Contract("Contract".into()),
Parameter::Methods(vec![
method("myMethod(uint256,bool)", "my_renamed_method"),
method("myOtherMethod()", "my_other_renamed_method"),
]),
Parameter::EventDerives(vec![
"Asdf".into(),
"a :: B".into(),
"a :: b :: c :: D".into()
])
],
},
);
}
#[test]
fn duplicate_method_rename_error() {
contract_args_err!(
"artifact.json",
"abi.json",
methods {
myMethod(uint256) as my_method_1;
myMethod(uint256) as my_method_2;
}
);
contract_args_err!(
"artifact.json",
"abi.json",
methods {
myMethod1(uint256) as my_method;
myMethod2(uint256) as my_method;
@ -310,7 +302,7 @@ mod tests {
#[test]
fn method_invalid_method_parameter_type() {
contract_args_err!(
"artifact.json",
"abi.json",
methods {
myMethod(invalid) as my_method;
}

View File

@ -15,19 +15,19 @@ use syn::{parse::Error, parse_macro_input};
/// an Ethereum contract ABI or a path. Note that this path is rooted in
/// the crate's root `CARGO_MANIFEST_DIR`.
///
/// ```ignore
/// # Examples
///
/// ```no_run
/// // ABI Path
/// abigen!(MyContract, "MyContract.json");
/// ```
///
/// Alternatively, other sources may be used, for full details consult the
/// `ethcontract-generate::source` documentation. Some basic examples:
///
/// ```ignore
/// // HTTP(S) source
/// abigen!(MyContract, "https://my.domain.local/path/to/contract.json")
///
/// // Etherscan.io
/// abigen!(MyContract, "etherscan:0x0001020304050607080910111213141516171819");
/// abigen!(MyContract, "https://etherscan.io/address/0x0001020304050607080910111213141516171819");
///
/// // npmjs
/// abigen!(MyContract, "npm:@org/package@1.0.0/path/to/contract.json")
/// ```
@ -45,19 +45,16 @@ use syn::{parse::Error, parse_macro_input};
/// - `event_derives`: A list of additional derives that should be added to
/// contract event structs and enums.
///
/// ```ignore
/// ```no_run
/// abigen!(
/// MyContractInstance,
/// "build/contracts/MyContract.json",
/// MyContract,
/// "path/to/MyContract.json",
/// methods {
/// myMethod(uint256,bool) as my_renamed_method;
/// },
/// event_derives (serde::Deserialize, serde::Serialize),
/// );
/// ```
///
/// See [`ethers-contract-abigen`](ethers-contract-abigen) module level documentation for additional
/// information.
#[proc_macro]
pub fn abigen(input: TokenStream) -> TokenStream {
let args = parse_macro_input!(input as Spanned<ContractArgs>);