test(abigen): re-enable tests
This commit is contained in:
parent
aa454b945b
commit
7dbc2d4f25
|
@ -15,7 +15,7 @@ ethers-core = { version = "0.1.0", path = "../ethers-core" }
|
||||||
serde = { version = "1.0.110", default-features = false }
|
serde = { version = "1.0.110", default-features = false }
|
||||||
rustc-hex = { version = "2.1.0", default-features = false }
|
rustc-hex = { version = "2.1.0", default-features = false }
|
||||||
thiserror = { version = "1.0.19", 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 }
|
tokio = { version = "0.2.21", default-features = false }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -107,13 +107,13 @@ impl Parse for Parameter {
|
||||||
if !signatures.insert(method.signature.clone()) {
|
if !signatures.insert(method.signature.clone()) {
|
||||||
return Err(ParseError::new(
|
return Err(ParseError::new(
|
||||||
method.span(),
|
method.span(),
|
||||||
"duplicate method signature in `ethcontract::contract!` macro invocation",
|
"duplicate method signature in `abigen!` macro invocation",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
if !aliases.insert(method.alias.clone()) {
|
if !aliases.insert(method.alias.clone()) {
|
||||||
return Err(ParseError::new(
|
return Err(ParseError::new(
|
||||||
method.span(),
|
method.span(),
|
||||||
"duplicate method alias in `ethcontract::contract!` macro invocation",
|
"duplicate method alias in `abigen!` macro invocation",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
methods.push(method.into_inner())
|
methods.push(method.into_inner())
|
||||||
|
@ -206,13 +206,13 @@ mod tests {
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
// macro_rules! contract_args {
|
macro_rules! contract_args {
|
||||||
// ($($arg:tt)*) => {
|
($($arg:tt)*) => {
|
||||||
// contract_args_result!($($arg)*)
|
contract_args_result!($($arg)*)
|
||||||
// .expect("failed to parse contract args")
|
.expect("failed to parse contract args")
|
||||||
// .into_inner()
|
.into_inner()
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|
||||||
macro_rules! contract_args_err {
|
macro_rules! contract_args_err {
|
||||||
($($arg:tt)*) => {
|
($($arg:tt)*) => {
|
||||||
|
@ -229,77 +229,69 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn parse_contract_args() {
|
fn parse_contract_args() {
|
||||||
// let args = contract_args!("path/to/artifact.json");
|
let args = contract_args!(TestContract, "path/to/abi.json");
|
||||||
// assert_eq!(args.artifact_path, "path/to/artifact.json");
|
assert_eq!(args.name, "TestContract");
|
||||||
// }
|
assert_eq!(args.abi, "path/to/abi.json");
|
||||||
|
}
|
||||||
|
|
||||||
// #[test]
|
#[test]
|
||||||
// fn crate_parameter_accepts_keywords() {
|
fn parse_contract_args_with_defaults() {
|
||||||
// let args = contract_args!("artifact.json", crate = crate);
|
let args = contract_args!(TestContract, "[{}]");
|
||||||
// assert_eq!(args.parameters, &[Parameter::Crate("crate".into())]);
|
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]
|
||||||
// #[test]
|
fn parse_contract_args_with_parameters() {
|
||||||
// fn parse_contract_args_with_defaults() {
|
let args = contract_args!(
|
||||||
// let args = contract_args!("artifact.json");
|
TestContract,
|
||||||
// assert_eq!(
|
"abi.json",
|
||||||
// args,
|
methods {
|
||||||
// ContractArgs {
|
myMethod(uint256, bool) as my_renamed_method;
|
||||||
// visibility: None,
|
myOtherMethod() as my_other_renamed_method;
|
||||||
// parameters: vec![],
|
},
|
||||||
// },
|
event_derives (Asdf, a::B, a::b::c::D)
|
||||||
// );
|
);
|
||||||
// }
|
assert_eq!(
|
||||||
|
args,
|
||||||
// #[test]
|
ContractArgs {
|
||||||
// fn parse_contract_args_with_parameters() {
|
name: "TestContract".to_string(),
|
||||||
// let args = contract_args!(
|
abi: "abi.json".to_string(),
|
||||||
// pub(crate) "artifact.json",
|
parameters: vec![
|
||||||
// crate = foobar,
|
// Parameter::Contract("Contract".into()),
|
||||||
// mod = contract,
|
Parameter::Methods(vec![
|
||||||
// contract = Contract,
|
method("myMethod(uint256,bool)", "my_renamed_method"),
|
||||||
// methods {
|
method("myOtherMethod()", "my_other_renamed_method"),
|
||||||
// myMethod(uint256, bool) as my_renamed_method;
|
]),
|
||||||
// myOtherMethod() as my_other_renamed_method;
|
Parameter::EventDerives(vec![
|
||||||
// },
|
"Asdf".into(),
|
||||||
// event_derives (Asdf, a::B, a::b::c::D)
|
"a :: B".into(),
|
||||||
// );
|
"a :: b :: c :: D".into()
|
||||||
// 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]
|
#[test]
|
||||||
fn duplicate_method_rename_error() {
|
fn duplicate_method_rename_error() {
|
||||||
contract_args_err!(
|
contract_args_err!(
|
||||||
"artifact.json",
|
"abi.json",
|
||||||
methods {
|
methods {
|
||||||
myMethod(uint256) as my_method_1;
|
myMethod(uint256) as my_method_1;
|
||||||
myMethod(uint256) as my_method_2;
|
myMethod(uint256) as my_method_2;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
contract_args_err!(
|
contract_args_err!(
|
||||||
"artifact.json",
|
"abi.json",
|
||||||
methods {
|
methods {
|
||||||
myMethod1(uint256) as my_method;
|
myMethod1(uint256) as my_method;
|
||||||
myMethod2(uint256) as my_method;
|
myMethod2(uint256) as my_method;
|
||||||
|
@ -310,7 +302,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn method_invalid_method_parameter_type() {
|
fn method_invalid_method_parameter_type() {
|
||||||
contract_args_err!(
|
contract_args_err!(
|
||||||
"artifact.json",
|
"abi.json",
|
||||||
methods {
|
methods {
|
||||||
myMethod(invalid) as my_method;
|
myMethod(invalid) as my_method;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
/// an Ethereum contract ABI or a path. Note that this path is rooted in
|
||||||
/// the crate's root `CARGO_MANIFEST_DIR`.
|
/// the crate's root `CARGO_MANIFEST_DIR`.
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```no_run
|
||||||
|
/// // ABI Path
|
||||||
/// abigen!(MyContract, "MyContract.json");
|
/// 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
|
/// // HTTP(S) source
|
||||||
/// abigen!(MyContract, "https://my.domain.local/path/to/contract.json")
|
/// abigen!(MyContract, "https://my.domain.local/path/to/contract.json")
|
||||||
|
///
|
||||||
/// // Etherscan.io
|
/// // Etherscan.io
|
||||||
/// abigen!(MyContract, "etherscan:0x0001020304050607080910111213141516171819");
|
/// abigen!(MyContract, "etherscan:0x0001020304050607080910111213141516171819");
|
||||||
/// abigen!(MyContract, "https://etherscan.io/address/0x0001020304050607080910111213141516171819");
|
/// abigen!(MyContract, "https://etherscan.io/address/0x0001020304050607080910111213141516171819");
|
||||||
|
///
|
||||||
/// // npmjs
|
/// // npmjs
|
||||||
/// abigen!(MyContract, "npm:@org/package@1.0.0/path/to/contract.json")
|
/// 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
|
/// - `event_derives`: A list of additional derives that should be added to
|
||||||
/// contract event structs and enums.
|
/// contract event structs and enums.
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```no_run
|
||||||
/// abigen!(
|
/// abigen!(
|
||||||
/// MyContractInstance,
|
/// MyContract,
|
||||||
/// "build/contracts/MyContract.json",
|
/// "path/to/MyContract.json",
|
||||||
/// methods {
|
/// methods {
|
||||||
/// myMethod(uint256,bool) as my_renamed_method;
|
/// myMethod(uint256,bool) as my_renamed_method;
|
||||||
/// },
|
/// },
|
||||||
/// event_derives (serde::Deserialize, serde::Serialize),
|
/// event_derives (serde::Deserialize, serde::Serialize),
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
///
|
|
||||||
/// See [`ethers-contract-abigen`](ethers-contract-abigen) module level documentation for additional
|
|
||||||
/// information.
|
|
||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
pub fn abigen(input: TokenStream) -> TokenStream {
|
pub fn abigen(input: TokenStream) -> TokenStream {
|
||||||
let args = parse_macro_input!(input as Spanned<ContractArgs>);
|
let args = parse_macro_input!(input as Spanned<ContractArgs>);
|
||||||
|
|
Loading…
Reference in New Issue