Skip to content

Commit

Permalink
Split constructor arguments for IdentityWallet
Browse files Browse the repository at this point in the history
Related to: #376
  • Loading branch information
weilbith committed May 15, 2020
1 parent 40dbeb4 commit ddcc37d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 44 deletions.
6 changes: 4 additions & 2 deletions src/TLNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/wallets/IdentityWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions tests/e2e/Identity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
49 changes: 13 additions & 36 deletions tests/unit/IdentityWallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down Expand Up @@ -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())
})
Expand All @@ -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'
)
})
})
})

Expand Down

0 comments on commit ddcc37d

Please sign in to comment.