Skip to content

Commit

Permalink
Fix a bunch of subxt-tests rust warnings (hyperledger-solang#1380)
Browse files Browse the repository at this point in the history
Signed-off-by: Sean Young <sean@mess.org>
  • Loading branch information
seanyoung authored Jun 22, 2023
1 parent 256b76e commit 316bfa3
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 112 deletions.
4 changes: 2 additions & 2 deletions integration/subxt-tests/src/cases/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async fn case() -> anyhow::Result<()> {
users.push((name, rnd_addr, id, perms));
}

let (name, addr, id, perms) = users.choose(&mut thread_rng()).unwrap();
let (_name, _addr, id, _perms) = users.choose(&mut thread_rng()).unwrap();

let output = contract
.try_call(
Expand All @@ -78,7 +78,7 @@ async fn case() -> anyhow::Result<()> {
)
.await?;

let (name, addr, id, perms) =
let (_name, _addr, id, perms) =
<(String, AccountId32, u64, Vec<u8>)>::decode(&mut output.as_bytes_ref())?;

if !perms.is_empty() {
Expand Down
4 changes: 2 additions & 2 deletions integration/subxt-tests/src/cases/balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async fn case() -> anyhow::Result<()> {
&api,
sp_keyring::AccountKeyring::Alice,
0,
&|t: &ContractMessageTranscoder| {
&|_: &ContractMessageTranscoder| {
let mut s = keccak_256(b"transfer(address,uint128)")[..4].to_vec();
dave.encode_to(&mut s);
20000_u128.encode_to(&mut s);
Expand All @@ -77,7 +77,7 @@ async fn case() -> anyhow::Result<()> {
&api,
sp_keyring::AccountKeyring::Alice,
0,
&|t: &ContractMessageTranscoder| {
&|_: &ContractMessageTranscoder| {
let mut s = keccak_256(b"send(address,uint128)")[..4].to_vec();
dave.encode_to(&mut s);
10000_u128.encode_to(&mut s);
Expand Down
11 changes: 4 additions & 7 deletions integration/subxt-tests/src/cases/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async fn case() -> anyhow::Result<()> {
sp_keyring::AccountKeyring::Alice,
0,
&|t: &ContractMessageTranscoder| {
t.encode("hash_ripemd160", [format!("0x{}", hex::encode(&input_str))])
t.encode("hash_ripemd160", [format!("0x{}", hex::encode(input_str))])
.unwrap()
},
)
Expand All @@ -47,7 +47,7 @@ async fn case() -> anyhow::Result<()> {
sp_keyring::AccountKeyring::Alice,
0,
&|t: &ContractMessageTranscoder| {
t.encode("hash_sha256", [format!("0x{}", hex::encode(&input_str))])
t.encode("hash_sha256", [format!("0x{}", hex::encode(input_str))])
.unwrap()
},
)
Expand All @@ -63,11 +63,8 @@ async fn case() -> anyhow::Result<()> {
sp_keyring::AccountKeyring::Alice,
0,
&|t: &ContractMessageTranscoder| {
t.encode(
"hash_kecccak256",
[format!("0x{}", hex::encode(&input_str))],
)
.unwrap()
t.encode("hash_kecccak256", [format!("0x{}", hex::encode(input_str))])
.unwrap()
},
)
.await?;
Expand Down
12 changes: 4 additions & 8 deletions integration/subxt-tests/src/cases/builtins2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ async fn case() -> anyhow::Result<()> {
// check blake2_128
let input_str = "Call me Ishmael.";

let selector = transcoder.encode(
"hash_blake2_128",
[format!("0x{}", hex::encode(&input_str))],
)?;
let selector =
transcoder.encode("hash_blake2_128", [format!("0x{}", hex::encode(input_str))])?;

let rv = ReadContract {
caller: sp_keyring::AccountKeyring::Alice,
Expand All @@ -46,10 +44,8 @@ async fn case() -> anyhow::Result<()> {
assert_eq!(rv.return_value, expected);

// check blake2_256
let selector = transcoder.encode(
"hash_blake2_256",
[format!("0x{}", hex::encode(&input_str))],
)?;
let selector =
transcoder.encode("hash_blake2_256", [format!("0x{}", hex::encode(input_str))])?;

let rv = ReadContract {
caller: sp_keyring::AccountKeyring::Alice,
Expand Down
6 changes: 3 additions & 3 deletions integration/subxt-tests/src/cases/external_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ async fn case() -> anyhow::Result<()> {
let c_callee = Contract::new("./contracts/callee.contract")?;
let t_callee = &c_callee.transcoder;

let c_callee2 = Contract::new("./contracts/callee2.contract")?;
let t_callee2 = &c_caller.transcoder;
let _c_callee2 = Contract::new("./contracts/callee2.contract")?;
let _t_callee2 = &c_caller.transcoder;

let selector = t_caller.encode::<_, String>("new", [])?;

Expand Down Expand Up @@ -53,7 +53,7 @@ async fn case() -> anyhow::Result<()> {
.await?;

// setX on callee
let selector = t_callee.encode::<_, String>("set_x", [format!("102")])?;
let selector = t_callee.encode::<_, String>("set_x", ["102".into()])?;

WriteContract {
caller: sp_keyring::AccountKeyring::Alice,
Expand Down
58 changes: 29 additions & 29 deletions integration/subxt-tests/src/cases/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ async fn case() -> anyhow::Result<()> {

// test res
#[derive(Encode, Decode)]
enum oper {
add,
sub,
mul,
div,
r#mod,
pow,
shl,
shr,
or,
and,
xor,
enum Oper {
Add,
Sub,
Mul,
Div,
Mod,
Pow,
Shl,
Shr,
Or,
And,
Xor,
}

let is_mul = c
Expand All @@ -68,9 +68,9 @@ async fn case() -> anyhow::Result<()> {
.expect("unable to find selector")
})
.await
.and_then(|rv| oper::decode(&mut rv.as_bytes_ref()).map_err(Into::into))?;
.and_then(|rv| Oper::decode(&mut rv.as_bytes_ref()).map_err(Into::into))?;

if let oper::div = return_div {
if let Oper::Div = return_div {
} else {
panic!("not div");
}
Expand Down Expand Up @@ -230,7 +230,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("d6435f25").expect("unable to decode selector");

oper::add.encode_to(&mut sel);
Oper::Add.encode_to(&mut sel);
U256::from_dec_str("1000")
.map(|o| o.encode_to(&mut sel))
.expect("unable to encode to selector");
Expand All @@ -250,7 +250,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("d6435f25").expect("unable to decode selector");

oper::sub.encode_to(&mut sel);
Oper::Sub.encode_to(&mut sel);
U256::from_dec_str("1000")
.map(|o| o.encode_to(&mut sel))
.expect("unable to encode to selector");
Expand All @@ -271,7 +271,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("d6435f25").expect("unable to decode selector");

oper::mul.encode_to(&mut sel);
Oper::Mul.encode_to(&mut sel);
U256::from_dec_str("1000")
.map(|o| o.encode_to(&mut sel))
.expect("unable to encode to selector");
Expand All @@ -291,7 +291,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("d6435f25").expect("unable to decode selector");

oper::div.encode_to(&mut sel);
Oper::Div.encode_to(&mut sel);
U256::from_dec_str("1000")
.map(|o| o.encode_to(&mut sel))
.expect("unable to encode to selector");
Expand All @@ -311,7 +311,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("d6435f25").expect("unable to decode selector");

oper::r#mod.encode_to(&mut sel);
Oper::Mod.encode_to(&mut sel);
U256::from_dec_str("1000")
.map(|o| o.encode_to(&mut sel))
.expect("unable to encode to selector");
Expand All @@ -330,7 +330,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("d6435f25").expect("unable to decode selector");

oper::shl.encode_to(&mut sel);
Oper::Shl.encode_to(&mut sel);
(!U256::from_dec_str("10000000000000").unwrap() + U256::one()).encode_to(&mut sel);

U256::from_dec_str("8")
Expand All @@ -348,7 +348,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("d6435f25").expect("unable to decode selector");

oper::shr.encode_to(&mut sel);
Oper::Shr.encode_to(&mut sel);
(!U256::from_dec_str("10000000000000").unwrap() + U256::one()).encode_to(&mut sel);

U256::from_dec_str("8")
Expand All @@ -370,7 +370,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("b446eacd").expect("unable to decode selector");

oper::add.encode_to(&mut sel);
Oper::Add.encode_to(&mut sel);
U256::from_dec_str("1000")
.map(|o| o.encode_to(&mut sel))
.expect("unable to encode to selector");
Expand All @@ -389,7 +389,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("b446eacd").expect("unable to decode selector");

oper::sub.encode_to(&mut sel);
Oper::Sub.encode_to(&mut sel);
U256::from_dec_str("1000")
.map(|o| o.encode_to(&mut sel))
.expect("unable to encode to selector");
Expand All @@ -408,7 +408,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("b446eacd").expect("unable to decode selector");

oper::mul.encode_to(&mut sel);
Oper::Mul.encode_to(&mut sel);
U256::from_dec_str("123456789")
.map(|o| o.encode_to(&mut sel))
.expect("unable to encode to selector");
Expand All @@ -427,7 +427,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("b446eacd").expect("unable to decode selector");

oper::div.encode_to(&mut sel);
Oper::Div.encode_to(&mut sel);
U256::from_dec_str("123456789")
.map(|o| o.encode_to(&mut sel))
.expect("unable to encode to selector");
Expand All @@ -446,7 +446,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("b446eacd").expect("unable to decode selector");

oper::r#mod.encode_to(&mut sel);
Oper::Mod.encode_to(&mut sel);
U256::from_dec_str("123456789")
.map(|o| o.encode_to(&mut sel))
.expect("unable to encode to selector");
Expand All @@ -465,7 +465,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("b446eacd").expect("unable to decode selector");

oper::pow.encode_to(&mut sel);
Oper::Pow.encode_to(&mut sel);
U256::from_dec_str("123456789")
.map(|o| o.encode_to(&mut sel))
.expect("unable to encode to selector");
Expand All @@ -488,7 +488,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("b446eacd").expect("unable to decode selector");

oper::shl.encode_to(&mut sel);
Oper::Shl.encode_to(&mut sel);
U256::from_dec_str("10000000000000")
.map(|o| o.encode_to(&mut sel))
.expect("unable to encode to selector");
Expand All @@ -507,7 +507,7 @@ async fn case() -> anyhow::Result<()> {
// since i256 is not supported by contract-metadata we need to manually supply the selector and encode its inputs
let mut sel = hex::decode("b446eacd").expect("unable to decode selector");

oper::shr.encode_to(&mut sel);
Oper::Shr.encode_to(&mut sel);
U256::from_dec_str("10000000000000")
.map(|o| o.encode_to(&mut sel))
.expect("unable to encode to selector");
Expand Down
22 changes: 11 additions & 11 deletions integration/subxt-tests/src/cases/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ async fn case() -> anyhow::Result<()> {
assert_eq!(res, (0, 0, 0, U256::zero()));

#[derive(Encode, Decode, PartialEq, Eq, Debug)]
enum enum_bar {
bar1,
bar2,
bar3,
bar4,
enum Bar {
Bar1,
Bar2,
Bar3,
Bar4,
}

let selector = transcoder.encode::<_, String>("get_values2", [])?;
Expand All @@ -64,7 +64,7 @@ async fn case() -> anyhow::Result<()> {
.execute(&api)
.await
.and_then(|e| {
<(U256, String, Vec<u8>, [u8; 4], enum_bar)>::decode(&mut e.return_value.as_bytes_ref())
<(U256, String, Vec<u8>, [u8; 4], Bar)>::decode(&mut e.return_value.as_bytes_ref())
.map_err(Into::into)
})?;

Expand All @@ -75,7 +75,7 @@ async fn case() -> anyhow::Result<()> {
"".into(),
hex::decode("b00b1e")?,
<_>::from_hex("00000000")?,
enum_bar::bar1
Bar::Bar1
)
);

Expand Down Expand Up @@ -127,7 +127,7 @@ async fn case() -> anyhow::Result<()> {
.execute(&api)
.await
.and_then(|e| {
<(U256, String, Vec<u8>, [u8; 4], enum_bar)>::decode(&mut e.return_value.as_bytes_ref())
<(U256, String, Vec<u8>, [u8; 4], Bar)>::decode(&mut e.return_value.as_bytes_ref())
.map_err(Into::into)
})?;

Expand All @@ -138,7 +138,7 @@ async fn case() -> anyhow::Result<()> {
"the course of true love never did run smooth".into(),
hex::decode("b00b1e")?,
<_>::from_hex("41424344")?,
enum_bar::bar2
Bar::Bar2
)
);

Expand Down Expand Up @@ -190,7 +190,7 @@ async fn case() -> anyhow::Result<()> {
.execute(&api)
.await
.and_then(|e| {
<(U256, String, Vec<u8>, [u8; 4], enum_bar)>::decode(&mut e.return_value.as_bytes_ref())
<(U256, String, Vec<u8>, [u8; 4], Bar)>::decode(&mut e.return_value.as_bytes_ref())
.map_err(Into::into)
})?;

Expand All @@ -201,7 +201,7 @@ async fn case() -> anyhow::Result<()> {
"".into(),
hex::decode("b0ff1e")?,
<_>::from_hex("61626364")?,
enum_bar::bar4
Bar::Bar4
)
);

Expand Down
Loading

0 comments on commit 316bfa3

Please sign in to comment.