Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing for Eth Backing Module #172

Merged
merged 17 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions srml/eth-backing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2018"
[dependencies]
# crates.io
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
hex = { version = "0.4", default-features = false }
#hex = { version = "0.4", default-features = false }
serde = { version = "1.0.101", optional = true }

# github.com
Expand Down Expand Up @@ -46,7 +46,7 @@ rlp = { package = "rlp", git = "https://github.com/darwinia-network/parity-commo
default = ["std"]
std = [
"codec/std",
"hex/std",
# "hex/std",
"serde/std",

"ethabi/std",
Expand Down
18 changes: 11 additions & 7 deletions srml/eth-backing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ decl_module! {
.clone()
.to_bytes()
.ok_or("Convert to Bytes - FAILED")?;
let decoded_sub_key = hex::decode(&raw_sub_key).map_err(|_| "Decode Address - FAILED")?;
// let decoded_sub_key = hex::decode(&raw_sub_key).map_err(|_| "Decode Address - FAILED")?;

T::DetermineAccountId::account_id_for(&decoded_sub_key)?
T::DetermineAccountId::account_id_for(&raw_sub_key[..])?
hackfisher marked this conversation as resolved.
Show resolved Hide resolved
};
let redeemed_ring = <RingBalanceOf<T>>::saturated_from(redeemed_amount);
let redeemed_positive_imbalance_ring = T::Ring::deposit_into_existing(&darwinia_account, redeemed_ring)?;
Expand Down Expand Up @@ -296,10 +296,10 @@ impl<T: Trait> Module<T> {
.to_bytes()
.ok_or("Convert to Bytes - FAILED")?;

// println!("raw_sub_key: {:?}", raw_sub_key);
let decoded_sub_key = hex::decode(&raw_sub_key).map_err(|_| "Decode Address - FAILED")?;
// let decoded_sub_key = hex::decode(&raw_sub_key).map_err(|_| "Decode Address - FAILED")?;

T::DetermineAccountId::account_id_for(&raw_sub_key)?
// println!("raw_sub_key: {:?}", raw_sub_key);
T::DetermineAccountId::account_id_for(&raw_sub_key[..])?
};

Ok((darwinia_account, redeemed_amount))
Expand All @@ -318,12 +318,16 @@ where
T::AccountId: rstd::convert::From<[u8; 32]> + AsRef<[u8]>,
{
fn account_id_for(decoded_sub_key: &[u8]) -> result::Result<T::AccountId, &'static str> {
if decoded_sub_key.len() != 32 {
if decoded_sub_key.len() != 33 {
hackfisher marked this conversation as resolved.
Show resolved Hide resolved
return Err("Address Length - MISMATCHED");
}

if decoded_sub_key[0] != 42 {
hackfisher marked this conversation as resolved.
Show resolved Hide resolved
return Err("Pubkey Prefix - MISMATCHED");
}

let mut r = [0u8; 32];
r.copy_from_slice(&decoded_sub_key[..]);
r.copy_from_slice(&decoded_sub_key[1..]);

let darwinia_account = r.into();

Expand Down
4 changes: 3 additions & 1 deletion srml/eth-backing/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ fn verify_parse_token_redeem_proof() {

assert_ok!(EthRelay::init_genesis_header(&header, 0x68de130d2c02a8_u64));

assert_eq!(EthBacking::parse_token_redeem_proof(&proof_record, "RingBurndropTokens"), Ok((AccountId::default(), 0)));
let expect_account_id = <Test as Trait>::DetermineAccountId::account_id_for(&hex!("2a92ae5b41feba5ee68a61449c557efa9e3b894a6461c058ec2de45429adb44546")).ok().unwrap();

assert_eq!(EthBacking::parse_token_redeem_proof(&proof_record, "RingBurndropTokens"), Ok((expect_account_id, 1234567891)));
});
}