import { Address , CeloTx , Signer } from '@celo/connect' ; import { normalizeAddressWith0x , privateKeyToAddress } from '@celo/utils/lib/address' ; import Web3 from 'web3' ; import { RemoteWallet } from './remote-wallet' ; export const PRIVATE_KEY1 = '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' ; export const ACCOUNT_ADDRESS1 = normalizeAddressWith0x ( privateKeyToAddress ( PRIVATE_KEY1 ) ) ; export const CHAIN_ID = 44378 ; export const TYPED_DATA = { types : { EIP712Domain : [ { name : 'name' , type : 'string' } , { name : 'version' , type : 'string' } , { name : 'chainId' , type : 'uint256' } , { name : 'verifyingContract' , type : 'address' } , ] , Person : [ { name : 'name' , type : 'string' } , { name : 'wallet' , type : 'address' } , ] , Mail : [ { name : 'from' , type : 'Person' } , { name : 'to' , type : 'Person' } , { name : 'contents' , type : 'string' } , ] } , primaryType : 'Mail' , domain : { name : 'Ether Mail' , version : '1' , chainId : 1 , verifyingContract : '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC' } , message : { from : { name : 'Cow' , wallet : '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826' } , to : { name : 'Bob' , wallet : '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB' } , contents : 'Hello, Bob!' } } ; class RemoteWalletImpl extends RemoteWallet < Signer > { protected async loadAccountSigners ( ) { return new Map < Address , Signer > ( ) ; } } describe ( 'RemoteWallet' , ( ) => { let wallet ; beforeEach ( ( ) => { wallet = new RemoteWalletImpl ( ) ; } ) ; describe ( 'without initializing' , ( ) => { const knownAddress = ACCOUNT_ADDRESS1 ; let celoTransaction ; beforeEach ( ( ) => { celoTransaction = { from : knownAddress , to : knownAddress , chainId : CHAIN_ID , value : Web3 . utils . toWei ( '1' , 'ether' ) , nonce : 0 , gas : '10' , gasPrice : '99' , feeCurrency : ACCOUNT_ADDRESS1 , gatewayFeeRecipient : ACCOUNT_ADDRESS1 , gatewayFee : '0x5678' , data : '0xabcdef' } ; } ) ; test ( 'fails calling getAccounts' , ( ) => { try { wallet . getAccounts ( ) ; throw new Error ( 'Expected exception to be thrown' ) ; } catch ( e ) { expect ( e . message ) . toBe ( 'wallet needs to be initialized first' ) ; } } ) ; test ( 'fails calling hasAccount' , ( ) => { try { wallet . hasAccount ( ACCOUNT_ADDRESS1 ) ; throw new Error ( 'Expected exception to be thrown' ) ; } catch ( e ) { expect ( e . message ) . toBe ( 'wallet needs to be initialized first' ) ; } } ) ; test ( 'fails calling signTransaction' , async ( ) => { await expect ( wallet . signTransaction ( celoTransaction ) ) . rejects . toThrowError ( ) ; } ) ; test ( 'fails calling signPersonalMessage' , async ( ) => { await expect ( wallet . signPersonalMessage ( ACCOUNT_ADDRESS1 , 'test' ) ) . rejects . toThrowError ( ) ; } ) ; test ( 'fails calling signTypedData' , async ( ) => { await expect ( wallet . signTypedData ( ACCOUNT_ADDRESS1 , TYPED_DATA ) ) . rejects . toThrowError ( ) ; } ) ; } ) ; } ) ;