From c1552388162d6e2076c4936019806e401606ac0b Mon Sep 17 00:00:00 2001 From: David Palm Date: Sat, 25 Aug 2018 11:55:27 +0200 Subject: [PATCH 1/6] Update dependencies: ethereum-types 0.4 and rustc-hex 2.0 Use hex! in tests --- Cargo.lock | 86 ++++++----- ethabi/Cargo.toml | 11 +- ethabi/src/decoder.rs | 177 ++++++++++++----------- ethabi/src/encoder.rs | 282 +++++++++++++++++++------------------ ethabi/src/filter.rs | 4 +- ethabi/src/function.rs | 2 +- ethabi/src/lib.rs | 4 + ethabi/src/signature.rs | 2 +- ethabi/src/token/strict.rs | 8 +- ethabi/src/token/token.rs | 4 +- ethabi/src/util.rs | 8 +- 11 files changed, 318 insertions(+), 270 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 859c6b1b0..7f3688189 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -79,11 +79,12 @@ dependencies = [ [[package]] name = "ethabi" -version = "5.1.1" +version = "5.1.2" dependencies = [ "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -96,7 +97,7 @@ version = "5.1.0" dependencies = [ "docopt 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethabi 5.1.1", + "ethabi 5.1.2", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -110,7 +111,7 @@ version = "5.1.0" name = "ethabi-derive" version = "5.1.0" dependencies = [ - "ethabi 5.1.1", + "ethabi 5.1.2", "heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "syn 0.12.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -120,7 +121,7 @@ dependencies = [ name = "ethabi-tests" version = "0.1.0" dependencies = [ - "ethabi 5.1.1", + "ethabi 5.1.2", "ethabi-contract 5.1.0", "ethabi-derive 5.1.0", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -140,16 +141,15 @@ dependencies = [ [[package]] name = "ethereum-types" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types-serialize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "fixed-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", - "uint 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -201,6 +201,23 @@ dependencies = [ "unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "hex-literal" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "hex-literal-impl" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "itoa" version = "0.4.0" @@ -229,6 +246,19 @@ name = "num-traits" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "proc-macro-hack" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro-hack-impl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "proc-macro-hack-impl" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "proc-macro2" version = "0.2.3" @@ -286,24 +316,8 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "rustc_version" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "semver-parser" -version = "0.7.0" +name = "rustc-hex" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -381,13 +395,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "uint" -version = "0.2.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -450,18 +464,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" "checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3" "checksum ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a93a43ce2e9f09071449da36bfa7a1b20b950ee344b6904ff23de493b03b386" -"checksum ethereum-types 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "53eabbad504e438e20b6559fd070d79b92cb31c02f994c7ecb05e9b2df716013" +"checksum ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "35b3c5a18bc5e73a32a110ac743ec04b02bbbcd3b71d3118d40a6113d509378a" "checksum ethereum-types-serialize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ac59a21a9ce98e188f3dace9eb67a6c4a3c67ec7fbc7218cb827852679dc002" "checksum fixed-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "362f32e2fbc5ed45f01a23ca074f936bb3aee4122a66e7118e8c3e965d96104c" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" "checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82" +"checksum hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4da5f0e01bd8a71a224a4eedecaacfcabda388dbb7a80faf04d3514287572d95" +"checksum hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1d340b6514f232f6db1bd16db65302a5278a04fef9ce867cb932e7e5fa21130a" "checksum itoa 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "92a9df60778f789c37f76778ae8d0a2471c41baa8b059d98a5873c978f549587" "checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" "checksum libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)" = "f54263ad99207254cf58b5f701ecb432c717445ea2ee8af387334bdd1a03fdff" "checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" "checksum num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dee092fcdf725aee04dd7da1d21debff559237d49ef1cb3e69bcb8ece44c7364" +"checksum proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ba8d4f9257b85eb6cdf13f055cea3190520aab1409ca2ab43493ea4820c25f0" +"checksum proc-macro-hack-impl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5cb6f960ad471404618e9817c0e5d10b1ae74cfdf01fab89ea0641fe7fb2892" "checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0" "checksum quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1eca14c727ad12702eb4b6bfb5a232287dcf8385cb8ca83a3eeaf6519c44c408" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" @@ -469,9 +487,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum regex-syntax 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b2550876c31dc914696a6c2e01cbce8afba79a93c8ae979d2fe051c0230b3756" "checksum rustc-demangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11fb43a206a04116ffd7cfcf9bcb941f8eb6cc7ff667272246b0a1c74259a3cb" "checksum rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0ceb8ce7a5e520de349e1fa172baeba4a9e8d5ef06c47471863530bc4972ee1e" -"checksum rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a54aa04a10c68c1c4eacb4337fd883b435997ede17a9385784b990777686b09a" -"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +"checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8" "checksum serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "4fe95aa0d46f04ce5c3a88bdcd4114ecd6144ed0b2725ebca2f1127744357807" "checksum serde_derive 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "23b163a6ce7e1aa897919f9d8e40bd1f8a6f95342ed57727ae31387a01a7a356" "checksum serde_derive_internals 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "370aa477297975243dc914d0b0e1234927520ec311de507a560fbd1c80f7ab8c" @@ -481,7 +497,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963" "checksum tiny-keccak 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "58911ed5eb275a8fd2f1f0418ed360a42f59329864b64e1e95377a9024498c01" "checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d" -"checksum uint 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6477b2716357758c176c36719023e1f9726974d762150e4fc0a9c8c75488c343" +"checksum uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "754ba11732b9161b94c41798e5197e5e75388d012f760c42adb5000353e98646" "checksum unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8083c594e02b8ae1654ae26f0ade5158b119bd88ad0e8227a5d8fcd72407946" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" diff --git a/ethabi/Cargo.toml b/ethabi/Cargo.toml index cc90f17ce..a4a72d914 100644 --- a/ethabi/Cargo.toml +++ b/ethabi/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ethabi" -version = "5.1.1" +version = "5.1.2" authors = ["Parity Technologies "] homepage = "https://github.com/paritytech/ethabi" license = "MIT" @@ -8,13 +8,16 @@ keywords = ["ethereum", "eth", "abi", "solidity", "cli"] description = "Easy to use conversion of ethereum contract calls to bytecode." [dependencies] -rustc-hex = "1.0" +rustc-hex = "2.0" serde = "1.0" serde_json = "1.0" serde_derive = "1.0" -tiny-keccak = "1.3" +tiny-keccak = "1.4" error-chain = { version = "0.11", default-features = false } -ethereum-types = "0.3" +ethereum-types = "0.4" + +[dev-dependencies] +hex-literal = "0.1.1" [features] backtrace = ["error-chain/backtrace"] diff --git a/ethabi/src/decoder.rs b/ethabi/src/decoder.rs index 78fc640c1..c19c9e5d4 100644 --- a/ethabi/src/decoder.rs +++ b/ethabi/src/decoder.rs @@ -205,12 +205,11 @@ fn decode_param(param: &ParamType, slices: &[[u8; 32]], offset: usize) -> Result #[cfg(test)] mod tests { - use hex::FromHex; use {decode, Token, ParamType}; #[test] fn decode_address() { - let encoded = "0000000000000000000000001111111111111111111111111111111111111111".from_hex().unwrap(); + let encoded = hex!("0000000000000000000000001111111111111111111111111111111111111111"); let address = Token::Address([0x11u8; 20].into()); let expected = vec![address]; let decoded = decode(&[ParamType::Address], &encoded).unwrap(); @@ -219,9 +218,10 @@ mod tests { #[test] fn decode_two_address() { - let encoded = ("".to_owned() + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000002222222222222222222222222222222222222222").from_hex().unwrap(); + let encoded = hex!(" + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + "); let address1 = Token::Address([0x11u8; 20].into()); let address2 = Token::Address([0x22u8; 20].into()); let expected = vec![address1, address2]; @@ -231,9 +231,10 @@ mod tests { #[test] fn decode_fixed_array_of_addresses() { - let encoded = ("".to_owned() + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000002222222222222222222222222222222222222222").from_hex().unwrap(); + let encoded = hex!(" + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + "); let address1 = Token::Address([0x11u8; 20].into()); let address2 = Token::Address([0x22u8; 20].into()); let expected = vec![Token::FixedArray(vec![address1, address2])]; @@ -243,7 +244,7 @@ mod tests { #[test] fn decode_uint() { - let encoded = "1111111111111111111111111111111111111111111111111111111111111111".from_hex().unwrap(); + let encoded = hex!("1111111111111111111111111111111111111111111111111111111111111111"); let uint = Token::Uint([0x11u8; 32].into()); let expected = vec![uint]; let decoded = decode(&[ParamType::Uint(32)], &encoded).unwrap(); @@ -252,7 +253,7 @@ mod tests { #[test] fn decode_int() { - let encoded = "1111111111111111111111111111111111111111111111111111111111111111".from_hex().unwrap(); + let encoded = hex!("1111111111111111111111111111111111111111111111111111111111111111"); let int = Token::Int([0x11u8; 32].into()); let expected = vec![int]; let decoded = decode(&[ParamType::Int(32)], &encoded).unwrap(); @@ -261,11 +262,12 @@ mod tests { #[test] fn decode_dynamic_array_of_addresses() { - let encoded = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000002222222222222222222222222222222222222222").from_hex().unwrap(); + let encoded = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + "); let address1 = Token::Address([0x11u8; 20].into()); let address2 = Token::Address([0x22u8; 20].into()); let addresses = Token::Array(vec![address1, address2]); @@ -276,13 +278,14 @@ mod tests { #[test] fn decode_dynamic_array_of_fixed_arrays() { - let encoded = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000002222222222222222222222222222222222222222" + - "0000000000000000000000003333333333333333333333333333333333333333" + - "0000000000000000000000004444444444444444444444444444444444444444").from_hex().unwrap(); + let encoded = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + 0000000000000000000000003333333333333333333333333333333333333333 + 0000000000000000000000004444444444444444444444444444444444444444 + "); let address1 = Token::Address([0x11u8; 20].into()); let address2 = Token::Address([0x22u8; 20].into()); let address3 = Token::Address([0x33u8; 20].into()); @@ -301,15 +304,16 @@ mod tests { #[test] fn decode_dynamic_array_of_dynamic_arrays() { - let encoded = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000080" + - "00000000000000000000000000000000000000000000000000000000000000c0" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "0000000000000000000000002222222222222222222222222222222222222222").from_hex().unwrap(); + let encoded = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000000000000000000000000000000000000000000080 + 00000000000000000000000000000000000000000000000000000000000000c0 + 0000000000000000000000000000000000000000000000000000000000000001 + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000000000000000000000000000000000000000000001 + 0000000000000000000000002222222222222222222222222222222222222222 + "); let address1 = Token::Address([0x11u8; 20].into()); let address2 = Token::Address([0x22u8; 20].into()); @@ -327,17 +331,18 @@ mod tests { #[test] fn decode_dynamic_array_of_dynamic_arrays2() { - let encoded = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000080" + - "00000000000000000000000000000000000000000000000000000000000000e0" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000002222222222222222222222222222222222222222" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000003333333333333333333333333333333333333333" + - "0000000000000000000000004444444444444444444444444444444444444444").from_hex().unwrap(); + let encoded = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000000000000000000000000000000000000000000080 + 00000000000000000000000000000000000000000000000000000000000000e0 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000003333333333333333333333333333333333333333 + 0000000000000000000000004444444444444444444444444444444444444444 + "); let address1 = Token::Address([0x11u8; 20].into()); let address2 = Token::Address([0x22u8; 20].into()); @@ -357,11 +362,12 @@ mod tests { #[test] fn decode_fixed_array_fixed_arrays() { - let encoded = ("".to_owned() + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000002222222222222222222222222222222222222222" + - "0000000000000000000000003333333333333333333333333333333333333333" + - "0000000000000000000000004444444444444444444444444444444444444444").from_hex().unwrap(); + let encoded = hex!(" + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + 0000000000000000000000003333333333333333333333333333333333333333 + 0000000000000000000000004444444444444444444444444444444444444444 + "); let address1 = Token::Address([0x11u8; 20].into()); let address2 = Token::Address([0x22u8; 20].into()); let address3 = Token::Address([0x33u8; 20].into()); @@ -383,15 +389,16 @@ mod tests { #[test] fn decode_fixed_array_of_dynamic_array_of_addresses() { - let encoded = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000040" + - "00000000000000000000000000000000000000000000000000000000000000a0" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000002222222222222222222222222222222222222222" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000003333333333333333333333333333333333333333" + - "0000000000000000000000004444444444444444444444444444444444444444").from_hex().unwrap(); + let encoded = hex!(" + 0000000000000000000000000000000000000000000000000000000000000040 + 00000000000000000000000000000000000000000000000000000000000000a0 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000003333333333333333333333333333333333333333 + 0000000000000000000000004444444444444444444444444444444444444444 + "); let address1 = Token::Address([0x11u8; 20].into()); let address2 = Token::Address([0x22u8; 20].into()); let address3 = Token::Address([0x33u8; 20].into()); @@ -413,8 +420,7 @@ mod tests { #[test] fn decode_fixed_bytes() { - let encoded = ("".to_owned() + - "1234000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap(); + let encoded = hex!("1234000000000000000000000000000000000000000000000000000000000000"); let bytes = Token::FixedBytes(vec![0x12, 0x34]); let expected = vec![bytes]; let decoded = decode(&[ParamType::FixedBytes(2)], &encoded).unwrap(); @@ -423,10 +429,11 @@ mod tests { #[test] fn decode_bytes() { - let encoded = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "1234000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap(); + let encoded = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000002 + 1234000000000000000000000000000000000000000000000000000000000000 + "); let bytes = Token::Bytes(vec![0x12, 0x34]); let expected = vec![bytes]; let decoded = decode(&[ParamType::Bytes], &encoded).unwrap(); @@ -435,14 +442,16 @@ mod tests { #[test] fn decode_bytes2() { - let encoded = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000040" + - "1000000000000000000000000000000000000000000000000000000000000000" + - "1000000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap(); - let bytes = Token::Bytes(("".to_owned() + - "1000000000000000000000000000000000000000000000000000000000000000" + - "1000000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap()); + let encoded = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000040 + 1000000000000000000000000000000000000000000000000000000000000000 + 1000000000000000000000000000000000000000000000000000000000000000 + "); + let bytes = Token::Bytes(hex!(" + 1000000000000000000000000000000000000000000000000000000000000000 + 1000000000000000000000000000000000000000000000000000000000000000 + ").to_vec()); let expected = vec![bytes]; let decoded = decode(&[ParamType::Bytes], &encoded).unwrap(); assert_eq!(decoded, expected); @@ -450,15 +459,16 @@ mod tests { #[test] fn decode_two_bytes() { - let encoded = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000040" + - "0000000000000000000000000000000000000000000000000000000000000080" + - "000000000000000000000000000000000000000000000000000000000000001f" + - "1000000000000000000000000000000000000000000000000000000000000200" + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0010000000000000000000000000000000000000000000000000000000000002").from_hex().unwrap(); - let bytes1 = Token::Bytes("10000000000000000000000000000000000000000000000000000000000002".from_hex().unwrap()); - let bytes2 = Token::Bytes("0010000000000000000000000000000000000000000000000000000000000002".from_hex().unwrap()); + let encoded = hex!(" + 0000000000000000000000000000000000000000000000000000000000000040 + 0000000000000000000000000000000000000000000000000000000000000080 + 000000000000000000000000000000000000000000000000000000000000001f + 1000000000000000000000000000000000000000000000000000000000000200 + 0000000000000000000000000000000000000000000000000000000000000020 + 0010000000000000000000000000000000000000000000000000000000000002 + "); + let bytes1 = Token::Bytes(hex!("10000000000000000000000000000000000000000000000000000000000002").to_vec()); + let bytes2 = Token::Bytes(hex!("0010000000000000000000000000000000000000000000000000000000000002").to_vec()); let expected = vec![bytes1, bytes2]; let decoded = decode(&[ParamType::Bytes, ParamType::Bytes], &encoded).unwrap(); assert_eq!(decoded, expected); @@ -466,10 +476,11 @@ mod tests { #[test] fn decode_string() { - let encoded = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000009" + - "6761766f66796f726b0000000000000000000000000000000000000000000000").from_hex().unwrap(); + let encoded = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000009 + 6761766f66796f726b0000000000000000000000000000000000000000000000 + "); let s = Token::String("gavofyork".to_owned()); let expected = vec![s]; let decoded = decode(&[ParamType::String], &encoded).unwrap(); diff --git a/ethabi/src/encoder.rs b/ethabi/src/encoder.rs index 07a157418..9c459cae5 100644 --- a/ethabi/src/encoder.rs +++ b/ethabi/src/encoder.rs @@ -175,7 +175,7 @@ mod tests { fn encode_address() { let address = Token::Address([0x11u8; 20].into()); let encoded = encode(&vec![address]); - let expected = "0000000000000000000000001111111111111111111111111111111111111111".from_hex().unwrap(); + let expected = hex!("0000000000000000000000001111111111111111111111111111111111111111"); assert_eq!(encoded, expected); } @@ -185,11 +185,12 @@ mod tests { let address2 = Token::Address([0x22u8; 20].into()); let addresses = Token::Array(vec![address1, address2]); let encoded = encode(&vec![addresses]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000002222222222222222222222222222222222222222").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + ").to_vec(); assert_eq!(encoded, expected); } @@ -199,9 +200,10 @@ mod tests { let address2 = Token::Address([0x22u8; 20].into()); let addresses = Token::FixedArray(vec![address1, address2]); let encoded = encode(&vec![addresses]); - let expected = ("".to_owned() + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000002222222222222222222222222222222222222222").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + ").to_vec(); assert_eq!(encoded, expected); } @@ -210,9 +212,10 @@ mod tests { let address1 = Token::Address([0x11u8; 20].into()); let address2 = Token::Address([0x22u8; 20].into()); let encoded = encode(&vec![address1, address2]); - let expected = ("".to_owned() + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000002222222222222222222222222222222222222222").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + ").to_vec(); assert_eq!(encoded, expected); } @@ -226,15 +229,16 @@ mod tests { let array1 = Token::Array(vec![address3, address4]); let fixed = Token::FixedArray(vec![array0, array1]); let encoded = encode(&vec![fixed]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000040" + - "00000000000000000000000000000000000000000000000000000000000000a0" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000002222222222222222222222222222222222222222" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000003333333333333333333333333333333333333333" + - "0000000000000000000000004444444444444444444444444444444444444444").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000000000000000000000000000000000000000000040 + 00000000000000000000000000000000000000000000000000000000000000a0 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000003333333333333333333333333333333333333333 + 0000000000000000000000004444444444444444444444444444444444444444 + ").to_vec(); assert_eq!(encoded, expected); } @@ -248,13 +252,14 @@ mod tests { let array1 = Token::FixedArray(vec![address3, address4]); let dynamic = Token::Array(vec![array0, array1]); let encoded = encode(&vec![dynamic]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000002222222222222222222222222222222222222222" + - "0000000000000000000000003333333333333333333333333333333333333333" + - "0000000000000000000000004444444444444444444444444444444444444444").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + 0000000000000000000000003333333333333333333333333333333333333333 + 0000000000000000000000004444444444444444444444444444444444444444 + ").to_vec(); assert_eq!(encoded, expected); } @@ -266,15 +271,16 @@ mod tests { let array1 = Token::Array(vec![address2]); let dynamic = Token::Array(vec![array0, array1]); let encoded = encode(&vec![dynamic]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000080" + - "00000000000000000000000000000000000000000000000000000000000000c0" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "0000000000000000000000002222222222222222222222222222222222222222").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000000000000000000000000000000000000000000080 + 00000000000000000000000000000000000000000000000000000000000000c0 + 0000000000000000000000000000000000000000000000000000000000000001 + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000000000000000000000000000000000000000000001 + 0000000000000000000000002222222222222222222222222222222222222222 + ").to_vec(); assert_eq!(encoded, expected); } @@ -288,17 +294,18 @@ mod tests { let array1 = Token::Array(vec![address3, address4]); let dynamic = Token::Array(vec![array0, array1]); let encoded = encode(&vec![dynamic]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000080" + - "00000000000000000000000000000000000000000000000000000000000000e0" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000002222222222222222222222222222222222222222" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000003333333333333333333333333333333333333333" + - "0000000000000000000000004444444444444444444444444444444444444444").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000000000000000000000000000000000000000000080 + 00000000000000000000000000000000000000000000000000000000000000e0 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000003333333333333333333333333333333333333333 + 0000000000000000000000004444444444444444444444444444444444444444 + ").to_vec(); assert_eq!(encoded, expected); } @@ -312,11 +319,12 @@ mod tests { let array1 = Token::FixedArray(vec![address3, address4]); let fixed = Token::FixedArray(vec![array0, array1]); let encoded = encode(&vec![fixed]); - let expected = ("".to_owned() + - "0000000000000000000000001111111111111111111111111111111111111111" + - "0000000000000000000000002222222222222222222222222222222222222222" + - "0000000000000000000000003333333333333333333333333333333333333333" + - "0000000000000000000000004444444444444444444444444444444444444444").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000001111111111111111111111111111111111111111 + 0000000000000000000000002222222222222222222222222222222222222222 + 0000000000000000000000003333333333333333333333333333333333333333 + 0000000000000000000000004444444444444444444444444444444444444444 + ").to_vec(); assert_eq!(encoded, expected); } @@ -327,11 +335,12 @@ mod tests { Token::Array(vec![]), Token::Array(vec![])] ); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000040" + - "0000000000000000000000000000000000000000000000000000000000000060" + - "0000000000000000000000000000000000000000000000000000000000000000" + - "0000000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000000000000000000000000000000000000000000040 + 0000000000000000000000000000000000000000000000000000000000000060 + 0000000000000000000000000000000000000000000000000000000000000000 + 0000000000000000000000000000000000000000000000000000000000000000 + ").to_vec(); assert_eq!(encoded, expected); // Nested empty arrays @@ -339,15 +348,16 @@ mod tests { Token::Array(vec![Token::Array(vec![])]), Token::Array(vec![Token::Array(vec![])]), ]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000040" + - "00000000000000000000000000000000000000000000000000000000000000a0" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "0000000000000000000000000000000000000000000000000000000000000080" + - "0000000000000000000000000000000000000000000000000000000000000000" + - "0000000000000000000000000000000000000000000000000000000000000001" + - "00000000000000000000000000000000000000000000000000000000000000e0" + - "0000000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000000000000000000000000000000000000000000040 + 00000000000000000000000000000000000000000000000000000000000000a0 + 0000000000000000000000000000000000000000000000000000000000000001 + 0000000000000000000000000000000000000000000000000000000000000080 + 0000000000000000000000000000000000000000000000000000000000000000 + 0000000000000000000000000000000000000000000000000000000000000001 + 00000000000000000000000000000000000000000000000000000000000000e0 + 0000000000000000000000000000000000000000000000000000000000000000 + ").to_vec(); assert_eq!(encoded, expected); } @@ -355,10 +365,11 @@ mod tests { fn encode_bytes() { let bytes = Token::Bytes(vec![0x12, 0x34]); let encoded = encode(&vec![bytes]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "1234000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000002 + 1234000000000000000000000000000000000000000000000000000000000000 + ").to_vec(); assert_eq!(encoded, expected); } @@ -366,8 +377,7 @@ mod tests { fn encode_fixed_bytes() { let bytes = Token::FixedBytes(vec![0x12, 0x34]); let encoded = encode(&vec![bytes]); - let expected = ("".to_owned() + - "1234000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap(); + let expected = hex!("1234000000000000000000000000000000000000000000000000000000000000"); assert_eq!(encoded, expected); } @@ -375,50 +385,55 @@ mod tests { fn encode_string() { let s = Token::String("gavofyork".to_owned()); let encoded = encode(&vec![s]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000009" + - "6761766f66796f726b0000000000000000000000000000000000000000000000").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000009 + 6761766f66796f726b0000000000000000000000000000000000000000000000 + ").to_vec(); assert_eq!(encoded, expected); } #[test] fn encode_bytes2() { - let bytes = Token::Bytes("10000000000000000000000000000000000000000000000000000000000002".from_hex().unwrap()); + let bytes = Token::Bytes(hex!("10000000000000000000000000000000000000000000000000000000000002").to_vec()); let encoded = encode(&vec![bytes]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "000000000000000000000000000000000000000000000000000000000000001f" + - "1000000000000000000000000000000000000000000000000000000000000200").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 000000000000000000000000000000000000000000000000000000000000001f + 1000000000000000000000000000000000000000000000000000000000000200 + ").to_vec(); assert_eq!(encoded, expected); } #[test] fn encode_bytes3() { - let bytes = Token::Bytes(("".to_owned() + - "1000000000000000000000000000000000000000000000000000000000000000" + - "1000000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap()); + let bytes = Token::Bytes(hex!(" + 1000000000000000000000000000000000000000000000000000000000000000 + 1000000000000000000000000000000000000000000000000000000000000000 + ").to_vec()); let encoded = encode(&vec![bytes]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0000000000000000000000000000000000000000000000000000000000000040" + - "1000000000000000000000000000000000000000000000000000000000000000" + - "1000000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000000000000000000000000000000000000000000020 + 0000000000000000000000000000000000000000000000000000000000000040 + 1000000000000000000000000000000000000000000000000000000000000000 + 1000000000000000000000000000000000000000000000000000000000000000 + ").to_vec(); assert_eq!(encoded, expected); } #[test] fn encode_two_bytes() { - let bytes1 = Token::Bytes("10000000000000000000000000000000000000000000000000000000000002".from_hex().unwrap()); - let bytes2 = Token::Bytes("0010000000000000000000000000000000000000000000000000000000000002".from_hex().unwrap()); + let bytes1 = Token::Bytes(hex!("10000000000000000000000000000000000000000000000000000000000002").to_vec()); + let bytes2 = Token::Bytes(hex!("0010000000000000000000000000000000000000000000000000000000000002").to_vec()); let encoded = encode(&vec![bytes1, bytes2]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000040" + - "0000000000000000000000000000000000000000000000000000000000000080" + - "000000000000000000000000000000000000000000000000000000000000001f" + - "1000000000000000000000000000000000000000000000000000000000000200" + - "0000000000000000000000000000000000000000000000000000000000000020" + - "0010000000000000000000000000000000000000000000000000000000000002").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000000000000000000000000000000000000000000040 + 0000000000000000000000000000000000000000000000000000000000000080 + 000000000000000000000000000000000000000000000000000000000000001f + 1000000000000000000000000000000000000000000000000000000000000200 + 0000000000000000000000000000000000000000000000000000000000000020 + 0010000000000000000000000000000000000000000000000000000000000002 + ").to_vec(); assert_eq!(encoded, expected); } @@ -427,8 +442,7 @@ mod tests { let mut uint = [0u8; 32]; uint[31] = 4; let encoded = encode(&vec![Token::Uint(uint.into())]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000004").from_hex().unwrap(); + let expected = hex!("0000000000000000000000000000000000000000000000000000000000000004"); assert_eq!(encoded, expected); } @@ -437,32 +451,30 @@ mod tests { let mut int = [0u8; 32]; int[31] = 4; let encoded = encode(&vec![Token::Int(int.into())]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000004").from_hex().unwrap(); + let expected = hex!("0000000000000000000000000000000000000000000000000000000000000004"); assert_eq!(encoded, expected); } #[test] fn encode_bool() { let encoded = encode(&vec![Token::Bool(true)]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000001").from_hex().unwrap(); + let expected = hex!("0000000000000000000000000000000000000000000000000000000000000001"); assert_eq!(encoded, expected); } #[test] fn encode_bool2() { let encoded = encode(&vec![Token::Bool(false)]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000000").from_hex().unwrap(); + let expected = hex!("0000000000000000000000000000000000000000000000000000000000000000"); assert_eq!(encoded, expected); } #[test] fn comprehensive_test() { - let bytes = ("".to_owned() + - "131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b" + - "131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b").from_hex().unwrap(); + let bytes = hex!(" + 131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b + 131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b + ").to_vec(); let encoded = encode(&vec![ Token::Int(5.into()), Token::Bytes(bytes.clone()), @@ -470,17 +482,18 @@ mod tests { Token::Bytes(bytes) ]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000080" + - "0000000000000000000000000000000000000000000000000000000000000003" + - "00000000000000000000000000000000000000000000000000000000000000e0" + - "0000000000000000000000000000000000000000000000000000000000000040" + - "131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b" + - "131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b" + - "0000000000000000000000000000000000000000000000000000000000000040" + - "131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b" + - "131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000000000000000000000000000000000000000000005 + 0000000000000000000000000000000000000000000000000000000000000080 + 0000000000000000000000000000000000000000000000000000000000000003 + 00000000000000000000000000000000000000000000000000000000000000e0 + 0000000000000000000000000000000000000000000000000000000000000040 + 131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b + 131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b + 0000000000000000000000000000000000000000000000000000000000000040 + 131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b + 131a3afc00d1b1e3461b955e53fc866dcf303b3eb9f4c16f89e388930f48134b + ").to_vec(); assert_eq!(encoded, expected); } @@ -506,19 +519,20 @@ mod tests { ]) ]); - let expected = ("".to_owned() + - "0000000000000000000000000000000000000000000000000000000000000001" + - "00000000000000000000000000000000000000000000000000000000000000c0" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000003" + - "0000000000000000000000000000000000000000000000000000000000000004" + - "0000000000000000000000000000000000000000000000000000000000000100" + - "0000000000000000000000000000000000000000000000000000000000000009" + - "6761766f66796f726b0000000000000000000000000000000000000000000000" + - "0000000000000000000000000000000000000000000000000000000000000003" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000006" + - "0000000000000000000000000000000000000000000000000000000000000007").from_hex().unwrap(); + let expected = hex!(" + 0000000000000000000000000000000000000000000000000000000000000001 + 00000000000000000000000000000000000000000000000000000000000000c0 + 0000000000000000000000000000000000000000000000000000000000000002 + 0000000000000000000000000000000000000000000000000000000000000003 + 0000000000000000000000000000000000000000000000000000000000000004 + 0000000000000000000000000000000000000000000000000000000000000100 + 0000000000000000000000000000000000000000000000000000000000000009 + 6761766f66796f726b0000000000000000000000000000000000000000000000 + 0000000000000000000000000000000000000000000000000000000000000003 + 0000000000000000000000000000000000000000000000000000000000000005 + 0000000000000000000000000000000000000000000000000000000000000006 + 0000000000000000000000000000000000000000000000000000000000000007 + ").to_vec(); assert_eq!(encoded, expected); } } diff --git a/ethabi/src/filter.rs b/ethabi/src/filter.rs index 25bd421c9..eb7bb7d20 100644 --- a/ethabi/src/filter.rs +++ b/ethabi/src/filter.rs @@ -100,12 +100,12 @@ impl Serialize for Topic { Topic::Any => Value::Null, Topic::OneOf(ref vec) => { let v = vec.iter() - .map(|h| format!("0x{}", h.to_hex())) + .map(|h| format!("0x{}", h.to_hex::())) .map(Value::String) .collect(); Value::Array(v) }, - Topic::This(ref hash) => Value::String(format!("0x{}", hash.to_hex())), + Topic::This(ref hash) => Value::String(format!("0x{}", hash.to_hex::())), }; value.serialize(serializer) } diff --git a/ethabi/src/function.rs b/ethabi/src/function.rs index cd792ef22..f269fcd39 100644 --- a/ethabi/src/function.rs +++ b/ethabi/src/function.rs @@ -75,7 +75,7 @@ mod tests { let mut uint = [0u8; 32]; uint[31] = 69; let encoded = func.encode_input(&[Token::Uint(uint.into()), Token::Bool(true)]).unwrap(); - let expected = "cdcd77c000000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001".from_hex().unwrap(); + let expected = hex!("cdcd77c000000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001").to_vec(); assert_eq!(encoded, expected); } } diff --git a/ethabi/src/lib.rs b/ethabi/src/lib.rs index 89871bad1..8d2e8d443 100644 --- a/ethabi/src/lib.rs +++ b/ethabi/src/lib.rs @@ -13,6 +13,10 @@ extern crate serde_derive; #[macro_use] extern crate error_chain; +#[cfg(test)] +#[macro_use] +extern crate hex_literal; + extern crate ethereum_types; pub mod param_type; diff --git a/ethabi/src/signature.rs b/ethabi/src/signature.rs index 436cf64a9..fc04a579d 100644 --- a/ethabi/src/signature.rs +++ b/ethabi/src/signature.rs @@ -35,6 +35,6 @@ mod tests { #[test] fn test_signature() { - assert_eq!("cdcd77c0".from_hex().unwrap(), short_signature("baz", &[ParamType::Uint(32), ParamType::Bool])); + assert_eq!(hex!("cdcd77c0"), short_signature("baz", &[ParamType::Uint(32), ParamType::Bool])); } } diff --git a/ethabi/src/token/strict.rs b/ethabi/src/token/strict.rs index b01030051..d07bb12dc 100644 --- a/ethabi/src/token/strict.rs +++ b/ethabi/src/token/strict.rs @@ -7,7 +7,7 @@ pub struct StrictTokenizer; impl Tokenizer for StrictTokenizer { fn tokenize_address(value: &str) -> Result<[u8; 20], Error> { - let hex = try!(value.from_hex()); + let hex : Vec = try!(value.from_hex()); match hex.len() == 20 { false => Err(ErrorKind::InvalidData.into()), true => { @@ -36,7 +36,7 @@ impl Tokenizer for StrictTokenizer { } fn tokenize_fixed_bytes(value: &str, len: usize) -> Result, Error> { - let hex = try!(value.from_hex()); + let hex : Vec = try!(value.from_hex()); match hex.len() == len { true => Ok(hex), false => Err(ErrorKind::InvalidData.into()), @@ -44,7 +44,7 @@ impl Tokenizer for StrictTokenizer { } fn tokenize_uint(value: &str) -> Result<[u8; 32], Error> { - let hex = try!(value.from_hex()); + let hex : Vec = try!(value.from_hex()); match hex.len() == 32 { true => { let mut uint = [0u8; 32]; @@ -56,7 +56,7 @@ impl Tokenizer for StrictTokenizer { } fn tokenize_int(value: &str) -> Result<[u8; 32], Error> { - let hex = try!(value.from_hex()); + let hex : Vec = try!(value.from_hex()); match hex.len() == 32 { true => { let mut int = [0u8; 32]; diff --git a/ethabi/src/token/token.rs b/ethabi/src/token/token.rs index 868fbfca8..edf04e61b 100644 --- a/ethabi/src/token/token.rs +++ b/ethabi/src/token/token.rs @@ -57,8 +57,8 @@ impl fmt::Display for Token { match *self { Token::Bool(b) => write!(f, "{}", b), Token::String(ref s) => write!(f, "{}", s), - Token::Address(ref a) => write!(f, "{}", a.to_hex()), - Token::Bytes(ref bytes) | Token::FixedBytes(ref bytes) => write!(f, "{}", bytes.to_hex()), + Token::Address(ref a) => write!(f, "{:x}", a), + Token::Bytes(ref bytes) | Token::FixedBytes(ref bytes) => write!(f, "{}", bytes.to_hex::()), Token::Uint(ref i) | Token::Int(ref i) => write!(f, "{:x}", i), Token::Array(ref arr) | Token::FixedArray(ref arr) => { let s = arr.iter() diff --git a/ethabi/src/util.rs b/ethabi/src/util.rs index a80f68123..0955497f3 100644 --- a/ethabi/src/util.rs +++ b/ethabi/src/util.rs @@ -50,9 +50,9 @@ mod tests { #[test] fn test_i32() { - assert_eq!("0000000000000000000000000000000000000000000000000000000000000000".from_hex().unwrap(), pad_i32(0).to_vec()); - assert_eq!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff".from_hex().unwrap(), pad_i32(-1).to_vec()); - assert_eq!("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe".from_hex().unwrap(), pad_i32(-2).to_vec()); - assert_eq!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00".from_hex().unwrap(), pad_i32(-256).to_vec()); + assert_eq!(hex!("0000000000000000000000000000000000000000000000000000000000000000").to_vec(), pad_i32(0).to_vec()); + assert_eq!(hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").to_vec(), pad_i32(-1).to_vec()); + assert_eq!(hex!("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe").to_vec(), pad_i32(-2).to_vec()); + assert_eq!(hex!("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00").to_vec(), pad_i32(-256).to_vec()); } } From bd7bbd5f89f58ac7e4ca82dbb6609b0100b6db51 Mon Sep 17 00:00:00 2001 From: David Palm Date: Mon, 27 Aug 2018 11:07:00 +0200 Subject: [PATCH 2/6] Tweak tiny versions --- Cargo.lock | 8 ++++---- contract/Cargo.toml | 2 +- derive/Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f3688189..6dd6bf1f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -105,11 +105,11 @@ dependencies = [ [[package]] name = "ethabi-contract" -version = "5.1.0" +version = "5.1.1" [[package]] name = "ethabi-derive" -version = "5.1.0" +version = "5.1.3" dependencies = [ "ethabi 5.1.2", "heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -122,8 +122,8 @@ name = "ethabi-tests" version = "0.1.0" dependencies = [ "ethabi 5.1.2", - "ethabi-contract 5.1.0", - "ethabi-derive 5.1.0", + "ethabi-contract 5.1.1", + "ethabi-derive 5.1.3", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/contract/Cargo.toml b/contract/Cargo.toml index 111f903a2..279fde438 100644 --- a/contract/Cargo.toml +++ b/contract/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ethabi-contract" -version = "5.1.0" +version = "5.1.1" authors = ["Parity Technologies "] homepage = "https://github.com/paritytech/ethabi" license = "MIT" diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 1a5c58709..513a98d48 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ethabi-derive" -version = "5.1.0" +version = "5.1.3" authors = ["Parity Technologies "] homepage = "https://github.com/paritytech/ethabi" license = "MIT" From 20eb86553a07bce7ff8b2e99fffb93bcb92f97e9 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Sun, 1 Apr 2018 14:36:22 +0200 Subject: [PATCH 3/6] Fix derive for String params. --- derive/src/lib.rs | 2 +- res/Validators.abi | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 7e81024e9..c4cabbcf9 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -229,7 +229,7 @@ fn template_param_type(input: &ParamType, index: usize) -> quote::Tokens { ParamType::Int(_) => quote! { #t_ident: Into }, ParamType::Uint(_) => quote! { #t_ident: Into }, ParamType::Bool => quote! { #t_ident: Into }, - ParamType::String => quote! { T{}: Into }, + ParamType::String => quote! { #t_ident: Into }, ParamType::Array(ref kind) => { let t = rust_type(&*kind); quote! { diff --git a/res/Validators.abi b/res/Validators.abi index 3e3a85e3c..c0a6483b0 100644 --- a/res/Validators.abi +++ b/res/Validators.abi @@ -68,5 +68,19 @@ ], "name": "Changed", "type": "event" + }, + { + "constant": false, + "inputs": [ + { + "name": "title", + "type": "string" + } + ], + "name": "setTitle", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" } ] From db39b93949ec8b669dfab9bc4661a0291ed8a721 Mon Sep 17 00:00:00 2001 From: David Palm Date: Tue, 28 Aug 2018 12:37:09 +0200 Subject: [PATCH 4/6] Cleanup --- .gitignore | 1 + Cargo.lock | 8 ++++---- derive/Cargo.toml | 2 +- ethabi/Cargo.toml | 2 +- ethabi/src/encoder.rs | 1 - ethabi/src/function.rs | 1 - ethabi/src/signature.rs | 1 - ethabi/src/util.rs | 1 - 8 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 6e55ad0a4..d0c2422e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ target *.swp *.swo +.vscode diff --git a/Cargo.lock b/Cargo.lock index 6dd6bf1f1..2428daf4c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,7 +88,7 @@ dependencies = [ "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -136,7 +136,7 @@ dependencies = [ "ethereum-types-serialize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "fixed-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -382,7 +382,7 @@ dependencies = [ [[package]] name = "tiny-keccak" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -495,7 +495,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" "checksum syn 0.12.14 (registry+https://github.com/rust-lang/crates.io-index)" = "8c5bc2d6ff27891209efa5f63e9de78648d7801f085e4653701a692ce938d6fd" "checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963" -"checksum tiny-keccak 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "58911ed5eb275a8fd2f1f0418ed360a42f59329864b64e1e95377a9024498c01" +"checksum tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e9175261fbdb60781fcd388a4d6cc7e14764a2b629a7ad94abb439aed223a44f" "checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d" "checksum uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "754ba11732b9161b94c41798e5197e5e75388d012f760c42adb5000353e98646" "checksum unicode-segmentation 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8083c594e02b8ae1654ae26f0ade5158b119bd88ad0e8227a5d8fcd72407946" diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 513a98d48..55a0af579 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -11,7 +11,7 @@ description = "Easy to use conversion of ethereum contract calls to bytecode." proc-macro = true [dependencies] -ethabi = { path = "../ethabi", version = "5.0" } +ethabi = { path = "../ethabi", version = "5.1" } heck = "0.3" syn = "0.12.12" quote = "0.4.2" diff --git a/ethabi/Cargo.toml b/ethabi/Cargo.toml index a4a72d914..bdfb9a104 100644 --- a/ethabi/Cargo.toml +++ b/ethabi/Cargo.toml @@ -12,7 +12,7 @@ rustc-hex = "2.0" serde = "1.0" serde_json = "1.0" serde_derive = "1.0" -tiny-keccak = "1.4" +tiny-keccak = "1.4.2" error-chain = { version = "0.11", default-features = false } ethereum-types = "0.4" diff --git a/ethabi/src/encoder.rs b/ethabi/src/encoder.rs index 9c459cae5..e9bf73e41 100644 --- a/ethabi/src/encoder.rs +++ b/ethabi/src/encoder.rs @@ -167,7 +167,6 @@ fn encode_token(token: &Token) -> Mediate { #[cfg(test)] mod tests { - use hex::FromHex; use util::pad_u32; use {Token, encode}; diff --git a/ethabi/src/function.rs b/ethabi/src/function.rs index f269fcd39..264b4205d 100644 --- a/ethabi/src/function.rs +++ b/ethabi/src/function.rs @@ -53,7 +53,6 @@ impl Function { #[cfg(test)] mod tests { - use hex::FromHex; use {Token, Param, Function, ParamType}; #[test] diff --git a/ethabi/src/signature.rs b/ethabi/src/signature.rs index fc04a579d..3993a8ed4 100644 --- a/ethabi/src/signature.rs +++ b/ethabi/src/signature.rs @@ -29,7 +29,6 @@ fn fill_signature(name: &str, params: &[ParamType], result: &mut [u8]) { #[cfg(test)] mod tests { - use hex::FromHex; use super::short_signature; use {ParamType}; diff --git a/ethabi/src/util.rs b/ethabi/src/util.rs index 0955497f3..600c59117 100644 --- a/ethabi/src/util.rs +++ b/ethabi/src/util.rs @@ -45,7 +45,6 @@ pub fn pad_i32(value: i32) -> [u8; 32] { #[cfg(test)] mod tests { - use hex::FromHex; use super::pad_i32; #[test] From 69882c8dc41caff6d2c2c9d8493eec35aa45cfff Mon Sep 17 00:00:00 2001 From: David Palm Date: Tue, 28 Aug 2018 12:51:24 +0200 Subject: [PATCH 5/6] Use error-chain 0.12 --- Cargo.lock | 8 ++++---- cli/Cargo.toml | 2 +- ethabi/Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2428daf4c..a663deae5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -71,7 +71,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "error-chain" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -81,7 +81,7 @@ dependencies = [ name = "ethabi" version = "5.1.2" dependencies = [ - "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -96,7 +96,7 @@ name = "ethabi-cli" version = "5.1.0" dependencies = [ "docopt 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi 5.1.2", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -462,7 +462,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" "checksum docopt 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d8acd393692c503b168471874953a2531df0e9ab77d0b6bbc582395743300a4a" "checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" -"checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3" +"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" "checksum ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a93a43ce2e9f09071449da36bfa7a1b20b950ee344b6904ff23de493b03b386" "checksum ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "35b3c5a18bc5e73a32a110ac743ec04b02bbbcd3b71d3118d40a6113d509378a" "checksum ethereum-types-serialize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ac59a21a9ce98e188f3dace9eb67a6c4a3c67ec7fbc7218cb827852679dc002" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 07250f542..d868fcf3f 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -13,7 +13,7 @@ serde = "1.0" serde_derive = "1.0" docopt = "0.8.1" ethabi = { version = "5", path = "../ethabi" } -error-chain = { version = "0.11.0", default-features = false } +error-chain = { version = "0.12.0", default-features = false } [features] backtrace = ["error-chain/backtrace"] diff --git a/ethabi/Cargo.toml b/ethabi/Cargo.toml index bdfb9a104..39d76d94c 100644 --- a/ethabi/Cargo.toml +++ b/ethabi/Cargo.toml @@ -13,7 +13,7 @@ serde = "1.0" serde_json = "1.0" serde_derive = "1.0" tiny-keccak = "1.4.2" -error-chain = { version = "0.11", default-features = false } +error-chain = { version = "0.12", default-features = false } ethereum-types = "0.4" [dev-dependencies] From 2998e3124ae27c6b2a63f46c68230572299ad613 Mon Sep 17 00:00:00 2001 From: debris Date: Wed, 4 Apr 2018 15:58:57 +0200 Subject: [PATCH 6/6] use syn::Index instead of syn::Ident for numbers --- Cargo.lock | 99 ++++++++++++++++++++++++++++++----------------- derive/src/lib.rs | 2 +- res/urlhint.abi | 6 +++ tests/src/lib.rs | 1 + 4 files changed, 72 insertions(+), 36 deletions(-) create mode 100644 res/urlhint.abi diff --git a/Cargo.lock b/Cargo.lock index a663deae5..9373389c7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,7 +13,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -24,7 +24,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -34,7 +34,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -59,8 +59,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -85,8 +85,8 @@ dependencies = [ "ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -99,8 +99,8 @@ dependencies = [ "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethabi 5.1.2", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -135,7 +135,7 @@ dependencies = [ "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types-serialize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "fixed-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -148,7 +148,7 @@ dependencies = [ "ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types-serialize 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "fixed-hash 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "uint 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -157,7 +157,7 @@ name = "ethereum-types-serialize" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -166,7 +166,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -220,7 +220,7 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -230,7 +230,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.39" +version = "0.2.40" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -238,7 +238,7 @@ name = "memchr" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -267,6 +267,14 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "proc-macro2" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "quote" version = "0.4.2" @@ -275,13 +283,21 @@ dependencies = [ "proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "quote" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -322,27 +338,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.33" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde_derive" -version = "1.0.33" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive_internals 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.12.14 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive_internals 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.13.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive_internals" -version = "0.21.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.12.14 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.13.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -351,9 +367,9 @@ version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "itoa 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -371,6 +387,16 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "syn" +version = "0.13.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "thread_local" version = "0.3.5" @@ -398,7 +424,7 @@ name = "uint" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -456,7 +482,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum backtrace 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ebbbf59b1c43eefa8c3ede390fcc36820b4999f7914104015be25025e0d62af2" "checksum backtrace-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "44585761d6161b0f57afc49482ab6bd067e4edef48c12a152c237eb0203f7661" "checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" -"checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23" +"checksum byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73b5bdfe7ee3ad0b99c9801d58807a9dbc9e09196365b0203853b99889ab3c87" "checksum cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "2b4911e4bdcb4100c7680e7e854ff38e23f1b34d4d9e079efae3da2801341ffc" "checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" "checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" @@ -473,27 +499,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82" "checksum hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4da5f0e01bd8a71a224a4eedecaacfcabda388dbb7a80faf04d3514287572d95" "checksum hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1d340b6514f232f6db1bd16db65302a5278a04fef9ce867cb932e7e5fa21130a" -"checksum itoa 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "92a9df60778f789c37f76778ae8d0a2471c41baa8b059d98a5873c978f549587" +"checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682" "checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" -"checksum libc 0.2.39 (registry+https://github.com/rust-lang/crates.io-index)" = "f54263ad99207254cf58b5f701ecb432c717445ea2ee8af387334bdd1a03fdff" +"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b" "checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" "checksum num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dee092fcdf725aee04dd7da1d21debff559237d49ef1cb3e69bcb8ece44c7364" "checksum proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ba8d4f9257b85eb6cdf13f055cea3190520aab1409ca2ab43493ea4820c25f0" "checksum proc-macro-hack-impl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5cb6f960ad471404618e9817c0e5d10b1ae74cfdf01fab89ea0641fe7fb2892" "checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0" +"checksum proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1b06e2f335f48d24442b35a19df506a835fb3547bc3c06ef27340da9acf5cae7" "checksum quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1eca14c727ad12702eb4b6bfb5a232287dcf8385cb8ca83a3eeaf6519c44c408" +"checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" "checksum regex 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "aec3f58d903a7d2a9dc2bf0e41a746f4530e0cab6b615494e058f67a3ef947fb" "checksum regex-syntax 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b2550876c31dc914696a6c2e01cbce8afba79a93c8ae979d2fe051c0230b3756" "checksum rustc-demangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11fb43a206a04116ffd7cfcf9bcb941f8eb6cc7ff667272246b0a1c74259a3cb" "checksum rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0ceb8ce7a5e520de349e1fa172baeba4a9e8d5ef06c47471863530bc4972ee1e" "checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8" -"checksum serde 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "4fe95aa0d46f04ce5c3a88bdcd4114ecd6144ed0b2725ebca2f1127744357807" -"checksum serde_derive 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "23b163a6ce7e1aa897919f9d8e40bd1f8a6f95342ed57727ae31387a01a7a356" -"checksum serde_derive_internals 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "370aa477297975243dc914d0b0e1234927520ec311de507a560fbd1c80f7ab8c" +"checksum serde 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "d3bcee660dcde8f52c3765dd9ca5ee36b4bf35470a738eb0bd5a8752b0389645" +"checksum serde_derive 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "f1711ab8b208541fa8de00425f6a577d90f27bb60724d2bb5fd911314af9668f" +"checksum serde_derive_internals 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "89b340a48245bc03ddba31d0ff1709c118df90edc6adabaca4aac77aea181cce" "checksum serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "5c508584d9913df116b91505eec55610a2f5b16e9ed793c46e4d0152872b3e74" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" "checksum syn 0.12.14 (registry+https://github.com/rust-lang/crates.io-index)" = "8c5bc2d6ff27891209efa5f63e9de78648d7801f085e4653701a692ce938d6fd" +"checksum syn 0.13.11 (registry+https://github.com/rust-lang/crates.io-index)" = "14f9bf6292f3a61d2c716723fdb789a41bbe104168e6f496dc6497e531ea1b9b" "checksum thread_local 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "279ef31c19ededf577bfd12dfae728040a21f635b06a24cd670ff510edd38963" "checksum tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e9175261fbdb60781fcd388a4d6cc7e14764a2b629a7ad94abb439aed223a44f" "checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d" diff --git a/derive/src/lib.rs b/derive/src/lib.rs index c4cabbcf9..409358178 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -300,7 +300,7 @@ fn from_token(kind: &ParamType, token: "e::Tokens) -> quote::Tokens { } }, ParamType::FixedBytes(size) => { - let size: syn::Ident = format!("{}", size).into(); + let size: syn::Index = size.into(); quote! { { let mut result = [0u8; #size]; diff --git a/res/urlhint.abi b/res/urlhint.abi new file mode 100644 index 000000000..629f166bb --- /dev/null +++ b/res/urlhint.abi @@ -0,0 +1,6 @@ +[ + {"constant":false,"inputs":[{"name":"_content","type":"bytes32"},{"name":"_url","type":"string"}],"name":"hintURL","outputs":[],"type":"function"}, + {"constant":false,"inputs":[{"name":"_content","type":"bytes32"},{"name":"_accountSlashRepo","type":"string"},{"name":"_commit","type":"bytes20"}],"name":"hint","outputs":[],"type":"function"}, + {"constant":true,"inputs":[{"name":"","type":"bytes32"}],"name":"entries","outputs":[{"name":"accountSlashRepo","type":"string"},{"name":"commit","type":"bytes20"},{"name":"owner","type":"address"}],"type":"function"}, + {"constant":false,"inputs":[{"name":"_content","type":"bytes32"}],"name":"unhint","outputs":[],"type":"function"} +] diff --git a/tests/src/lib.rs b/tests/src/lib.rs index 7225a918c..b064cd309 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -15,6 +15,7 @@ use_contract!(eip20, "Eip20", "../res/eip20.abi"); use_contract!(constructor, "Constructor", "../res/con.abi"); use_contract!(validators, "Validators", "../res/Validators.abi"); use_contract!(operations, "Operations", "../res/Operations.abi"); +use_contract!(urlhint, "UrlHint", "../res/urlhint.abi"); #[cfg(test)] mod tests {