@@ -203,7 +203,6 @@ impl Adapter for EthereumAdapter {
203
203
204
204
let sess = match & verified. payload . identity {
205
205
Some ( identity) => {
206
-
207
206
let contract_address = Address :: from_slice ( identity) ;
208
207
let ( _eloop, transport) = web3:: transports:: Http :: new ( & self . config . ethereum_network )
209
208
. map_err ( |_| map_error ( "failed to init http transport" ) ) ?;
@@ -214,7 +213,7 @@ impl Adapter for EthereumAdapter {
214
213
let privilege_level: U256 = contract
215
214
. query (
216
215
"privileges" ,
217
- ( verified. from . to_string ( ) , ) ,
216
+ ( Token :: Address ( Address :: from_slice ( verified. from . inner ( ) ) ) , ) ,
218
217
None ,
219
218
Options :: default ( ) ,
220
219
None ,
@@ -466,7 +465,7 @@ mod test {
466
465
}
467
466
468
467
#[ test]
469
- fn should_validate_channel_properly ( ) {
468
+ fn should_validate_valid_channel_properly ( ) {
470
469
let ( eloop, http) =
471
470
web3:: transports:: Http :: new ( "http://localhost:8545" ) . expect ( "failed to init transport" ) ;
472
471
eloop. into_remote ( ) ;
@@ -599,4 +598,62 @@ mod test {
599
598
. validate_channel ( & valid_channel)
600
599
. expect ( "failed to validate channel" ) ;
601
600
}
601
+
602
+ #[ test]
603
+ fn should_generate_session_from_token_with_identity ( ) {
604
+ // setup test payload
605
+ let mut eth_adapter = setup_eth_adapter ( None ) ;
606
+ eth_adapter. unlock ( ) . expect ( "should unlock eth adapter" ) ;
607
+
608
+ // deploy identity contract
609
+ let ( eloop, http) =
610
+ web3:: transports:: Http :: new ( "http://localhost:8545" ) . expect ( "failed to init transport" ) ;
611
+ eloop. into_remote ( ) ;
612
+
613
+ let web3 = web3:: Web3 :: new ( http) ;
614
+ // part of address used in initializing ganache-cli
615
+ let leader_account: Address = "Df08F82De32B8d460adbE8D72043E3a7e25A3B39"
616
+ . parse ( )
617
+ . 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
+
621
+ let identity_bytecode = include_str ! ( "../test/resources/identitybytecode.json" ) ;
622
+
623
+ // deploy identity contract
624
+ let identity_contract = Contract :: deploy ( web3. eth ( ) , & IDENTITY_ABI )
625
+ . expect ( "invalid token token contract" )
626
+ . confirmations ( 0 )
627
+ . options ( Options :: with ( |opt| {
628
+ opt. gas_price = Some ( 1 . into ( ) ) ;
629
+ opt. gas = Some ( 6_721_975 . into ( ) ) ;
630
+ } ) )
631
+ . execute ( identity_bytecode, (
632
+ Token :: Array ( vec ! [ Token :: Address ( eth_adapter_address) ] ) ,
633
+ Token :: Array ( vec ! [ Token :: Uint ( 1 . into( ) ) ] )
634
+ ) , leader_account)
635
+ . expect ( "Correct parameters are passed to the constructor." )
636
+ . wait ( )
637
+ . expect ( "failed to wait" ) ;
638
+
639
+ // identity contract address
640
+ let identity = <[ u8 ; 20 ] >:: from_hex ( & format ! ( "{:?}" , identity_contract. address( ) ) [ 2 ..] ) . expect ( "failed to deserialize address" ) ;
641
+
642
+ let payload = Payload {
643
+ id : eth_adapter. whoami ( ) . to_hex_checksummed_string ( ) ,
644
+ era : 100_000 ,
645
+ address : format ! ( "{:?}" , leader_account) ,
646
+ identity : Some ( identity) ,
647
+ } ;
648
+
649
+ let wallet = eth_adapter. wallet . clone ( ) ;
650
+ let response = ewt_sign ( & wallet. unwrap ( ) , & eth_adapter. keystore_pwd , & payload)
651
+ . expect ( "failed to generate ewt signature" ) ;
652
+
653
+ // verify since its with identity
654
+ let session = eth_adapter. session_from_token ( & response) . expect ( "failed generate session" ) ;
655
+ assert_eq ! ( session. uid. inner( ) , & identity) ;
656
+ }
657
+
658
+
602
659
}
0 commit comments