Skip to content

Commit bf3603d

Browse files
committed
fix: add ganache-cli setup, ethereum startup
1 parent 6f78a48 commit bf3603d

File tree

6 files changed

+654
-22
lines changed

6 files changed

+654
-22
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ target
44
*.iml
55
.idea
66
.old
7-
Migrant.toml
7+
Migrant.toml
8+
node_modules

Makefile.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = "true"
33
CARGO_MAKE_CLIPPY_ARGS = "--all-features -- -D warnings"
44

55
[tasks.pre-test]
6-
scripts = [
6+
script = [
7+
"npm install",
78
"./scripts/ethereum.sh"
89
]
910

adapter/src/ethereum.rs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,9 @@ impl Adapter for EthereumAdapter {
204204
let sess = match &verified.payload.identity {
205205
Some(identity) => {
206206
let contract_address = Address::from_slice(identity);
207-
let (_eloop, transport) = web3::transports::Http::new(&self.config.ethereum_network)
208-
.map_err(|_| map_error("failed to init http transport"))?;
207+
let (_eloop, transport) =
208+
web3::transports::Http::new(&self.config.ethereum_network)
209+
.map_err(|_| map_error("failed to init http transport"))?;
209210
let web3 = web3::Web3::new(transport);
210211
let contract = Contract::from_json(web3.eth(), contract_address, &IDENTITY_ABI)
211212
.map_err(|_| map_error("failed to init identity contract"))?;
@@ -607,17 +608,21 @@ mod test {
607608

608609
// deploy identity contract
609610
let (eloop, http) =
610-
web3::transports::Http::new("http://localhost:8545").expect("failed to init transport");
611+
web3::transports::Http::new("http://localhost:8545").expect("failed to init transport");
611612
eloop.into_remote();
612613

613614
let web3 = web3::Web3::new(http);
614615
// part of address used in initializing ganache-cli
615616
let leader_account: Address = "Df08F82De32B8d460adbE8D72043E3a7e25A3B39"
616617
.parse()
617618
.expect("failed to parse leader account");
618-
619-
let eth_adapter_address: Address = eth_adapter.whoami().to_hex_non_prefix_string().parse().expect("failed to parse eth adapter address");
620-
619+
620+
let eth_adapter_address: Address = eth_adapter
621+
.whoami()
622+
.to_hex_non_prefix_string()
623+
.parse()
624+
.expect("failed to parse eth adapter address");
625+
621626
let identity_bytecode = include_str!("../test/resources/identitybytecode.json");
622627

623628
// deploy identity contract
@@ -628,17 +633,22 @@ mod test {
628633
opt.gas_price = Some(1.into());
629634
opt.gas = Some(6_721_975.into());
630635
}))
631-
.execute(identity_bytecode, (
632-
Token::Array(vec![Token::Address(eth_adapter_address)]),
633-
Token::Array(vec![Token::Uint(1.into())])
634-
), leader_account)
636+
.execute(
637+
identity_bytecode,
638+
(
639+
Token::Array(vec![Token::Address(eth_adapter_address)]),
640+
Token::Array(vec![Token::Uint(1.into())]),
641+
),
642+
leader_account,
643+
)
635644
.expect("Correct parameters are passed to the constructor.")
636645
.wait()
637646
.expect("failed to wait");
638647

639648
// identity contract address
640-
let identity = <[u8; 20]>::from_hex(&format!("{:?}", identity_contract.address())[2..]).expect("failed to deserialize address");
641-
649+
let identity = <[u8; 20]>::from_hex(&format!("{:?}", identity_contract.address())[2..])
650+
.expect("failed to deserialize address");
651+
642652
let payload = Payload {
643653
id: eth_adapter.whoami().to_hex_checksummed_string(),
644654
era: 100_000,
@@ -649,11 +659,11 @@ mod test {
649659
let wallet = eth_adapter.wallet.clone();
650660
let response = ewt_sign(&wallet.unwrap(), &eth_adapter.keystore_pwd, &payload)
651661
.expect("failed to generate ewt signature");
652-
662+
653663
// verify since its with identity
654-
let session = eth_adapter.session_from_token(&response).expect("failed generate session");
664+
let session = eth_adapter
665+
.session_from_token(&response)
666+
.expect("failed generate session");
655667
assert_eq!(session.uid.inner(), &identity);
656668
}
657-
658-
659669
}

adapter/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::error::Error;
66

77
use chrono::{DateTime, Utc};
88
use ethabi::encode;
9-
use ethabi::token::{Token};
9+
use ethabi::token::Token;
1010
use hex::FromHex;
1111
use primitives::channel::ChannelError;
1212
use primitives::BigNum;
@@ -33,7 +33,7 @@ pub fn get_signable_state_root(
3333
) -> Result<[u8; 32], Box<dyn Error>> {
3434
let tokens = [
3535
Token::FixedBytes(channel_id.to_vec()),
36-
Token::FixedBytes(balance_root.to_vec())
36+
Token::FixedBytes(balance_root.to_vec()),
3737
];
3838

3939
let encoded = encode(&tokens).to_vec();
@@ -52,8 +52,8 @@ pub fn get_balance_leaf(acc: &ValidatorId, amnt: &BigNum) -> Result<[u8; 32], Bo
5252
Token::Address(Address::from_slice(acc.inner())),
5353
Token::Uint(
5454
U256::from_dec_str(&amnt.to_str_radix(10))
55-
.map_err(|_| ChannelError::InvalidArgument("failed to parse amt".into()))?
56-
)
55+
.map_err(|_| ChannelError::InvalidArgument("failed to parse amt".into()))?,
56+
),
5757
];
5858
let encoded = encode(&tokens).to_vec();
5959

0 commit comments

Comments
 (0)