From ddcc37dc107566b546ae2d647a83e018a871716f Mon Sep 17 00:00:00 2001 From: Thore Weilbier Date: Tue, 12 May 2020 19:06:00 +0200 Subject: [PATCH] Split constructor arguments for IdentityWallet Related to: #376 --- src/TLNetwork.ts | 6 ++-- src/wallets/IdentityWallet.ts | 4 ++- tests/e2e/Identity.test.ts | 8 ++--- tests/unit/IdentityWallet.test.ts | 49 ++++++++----------------------- 4 files changed, 23 insertions(+), 44 deletions(-) diff --git a/src/TLNetwork.ts b/src/TLNetwork.ts index c1e447aa..8d9bdd20 100644 --- a/src/TLNetwork.ts +++ b/src/TLNetwork.ts @@ -271,11 +271,13 @@ export class TLNetwork { let wallet: TLWallet if (walletType === WALLET_TYPE_IDENTITY) { - wallet = new IdentityWallet(provider, chainId, { + wallet = new IdentityWallet( + provider, + chainId, identityFactoryAddress, identityImplementationAddress, nonceMechanism - }) + ) } else if (walletType === WALLET_TYPE_ETHERS) { wallet = new EthersWallet(provider) } else { diff --git a/src/wallets/IdentityWallet.ts b/src/wallets/IdentityWallet.ts index 96390b8b..22b57534 100644 --- a/src/wallets/IdentityWallet.ts +++ b/src/wallets/IdentityWallet.ts @@ -51,7 +51,9 @@ export class IdentityWallet implements TLWallet { constructor( provider: TLProvider, chainId: number, - { identityFactoryAddress, identityImplementationAddress, nonceMechanism } + identityFactoryAddress: string, + identityImplementationAddress: string, + nonceMechanism: NonceMechanism ) { this.identityFactoryAddress = identityFactoryAddress this.identityImplementationAddress = identityImplementationAddress diff --git a/tests/e2e/Identity.test.ts b/tests/e2e/Identity.test.ts index d30a45cb..9a7d8661 100644 --- a/tests/e2e/Identity.test.ts +++ b/tests/e2e/Identity.test.ts @@ -141,11 +141,9 @@ describe('e2e', () => { const secondWallet = new IdentityWallet( relayProvider, tlNetworkConfigIdentity.chainId, - { - identityFactoryAddress, - identityImplementationAddress, - nonceMechanism: NonceMechanism.Random - } + identityFactoryAddress, + identityImplementationAddress, + NonceMechanism.Random ) const walletData = await secondWallet.create() await secondWallet.loadFrom(walletData) diff --git a/tests/unit/IdentityWallet.test.ts b/tests/unit/IdentityWallet.test.ts index 0249e6ed..d50e898e 100644 --- a/tests/unit/IdentityWallet.test.ts +++ b/tests/unit/IdentityWallet.test.ts @@ -43,11 +43,13 @@ describe('unit', () => { const init = () => { fakeTLProvider = new FakeTLProvider() - identityWallet = new IdentityWallet(fakeTLProvider, FAKE_CHAIN_ID, { - identityFactoryAddress: IDENTITY_FACTORY_ADDRESS, - identityImplementationAddress: IDENTITY_IMPLEMENTATION_ADDRESS, - nonceMechanism: NonceMechanism.Random - }) + identityWallet = new IdentityWallet( + fakeTLProvider, + FAKE_CHAIN_ID, + IDENTITY_FACTORY_ADDRESS, + IDENTITY_IMPLEMENTATION_ADDRESS, + NonceMechanism.Random + ) } describe('#create()', () => { @@ -233,30 +235,15 @@ describe('unit', () => { }) describe('#getNonce', () => { - const config = { - identityFactoryAddress: IDENTITY_FACTORY_ADDRESS, - identityImplementationAddress: IDENTITY_IMPLEMENTATION_ADDRESS - } - const randomNonceConfig = { - ...config, - nonceMechanism: NonceMechanism.Random - } - const countingNonceConfig = { - ...config, - nonceMechanism: NonceMechanism.Counting - } - const foreignNonceConfig = { - ...config, - nonceMechanism: 'foreign' - } - beforeEach(() => init()) it('should generate nonce with random mechanism', async () => { const randomIdentityWallet = new IdentityWallet( fakeTLProvider, FAKE_CHAIN_ID, - randomNonceConfig + IDENTITY_FACTORY_ADDRESS, + IDENTITY_IMPLEMENTATION_ADDRESS, + NonceMechanism.Random ) assert.isString(await randomIdentityWallet.getNonce()) }) @@ -265,24 +252,14 @@ describe('unit', () => { const countingIdentityWallet = new IdentityWallet( fakeTLProvider, FAKE_CHAIN_ID, - countingNonceConfig + IDENTITY_FACTORY_ADDRESS, + IDENTITY_IMPLEMENTATION_ADDRESS, + NonceMechanism.Counting ) const walletData = await countingIdentityWallet.create() await countingIdentityWallet.loadFrom(walletData) assert.isString(await countingIdentityWallet.getNonce()) }) - - it('should fail to generate nonce with foreign mechanism', async () => { - const foreignIdentityWallet = new IdentityWallet( - fakeTLProvider, - FAKE_CHAIN_ID, - foreignNonceConfig - ) - assert.isRejected( - foreignIdentityWallet.getNonce(), - 'Can not generate nonce for unknown mechanism: foreign' - ) - }) }) })