Skip to content

Commit ddcc37d

Browse files
committed
Split constructor arguments for IdentityWallet
Related to: #376
1 parent 40dbeb4 commit ddcc37d

File tree

4 files changed

+23
-44
lines changed

4 files changed

+23
-44
lines changed

src/TLNetwork.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,13 @@ export class TLNetwork {
271271
let wallet: TLWallet
272272

273273
if (walletType === WALLET_TYPE_IDENTITY) {
274-
wallet = new IdentityWallet(provider, chainId, {
274+
wallet = new IdentityWallet(
275+
provider,
276+
chainId,
275277
identityFactoryAddress,
276278
identityImplementationAddress,
277279
nonceMechanism
278-
})
280+
)
279281
} else if (walletType === WALLET_TYPE_ETHERS) {
280282
wallet = new EthersWallet(provider)
281283
} else {

src/wallets/IdentityWallet.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ export class IdentityWallet implements TLWallet {
5151
constructor(
5252
provider: TLProvider,
5353
chainId: number,
54-
{ identityFactoryAddress, identityImplementationAddress, nonceMechanism }
54+
identityFactoryAddress: string,
55+
identityImplementationAddress: string,
56+
nonceMechanism: NonceMechanism
5557
) {
5658
this.identityFactoryAddress = identityFactoryAddress
5759
this.identityImplementationAddress = identityImplementationAddress

tests/e2e/Identity.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,9 @@ describe('e2e', () => {
141141
const secondWallet = new IdentityWallet(
142142
relayProvider,
143143
tlNetworkConfigIdentity.chainId,
144-
{
145-
identityFactoryAddress,
146-
identityImplementationAddress,
147-
nonceMechanism: NonceMechanism.Random
148-
}
144+
identityFactoryAddress,
145+
identityImplementationAddress,
146+
NonceMechanism.Random
149147
)
150148
const walletData = await secondWallet.create()
151149
await secondWallet.loadFrom(walletData)

tests/unit/IdentityWallet.test.ts

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ describe('unit', () => {
4343

4444
const init = () => {
4545
fakeTLProvider = new FakeTLProvider()
46-
identityWallet = new IdentityWallet(fakeTLProvider, FAKE_CHAIN_ID, {
47-
identityFactoryAddress: IDENTITY_FACTORY_ADDRESS,
48-
identityImplementationAddress: IDENTITY_IMPLEMENTATION_ADDRESS,
49-
nonceMechanism: NonceMechanism.Random
50-
})
46+
identityWallet = new IdentityWallet(
47+
fakeTLProvider,
48+
FAKE_CHAIN_ID,
49+
IDENTITY_FACTORY_ADDRESS,
50+
IDENTITY_IMPLEMENTATION_ADDRESS,
51+
NonceMechanism.Random
52+
)
5153
}
5254

5355
describe('#create()', () => {
@@ -233,30 +235,15 @@ describe('unit', () => {
233235
})
234236

235237
describe('#getNonce', () => {
236-
const config = {
237-
identityFactoryAddress: IDENTITY_FACTORY_ADDRESS,
238-
identityImplementationAddress: IDENTITY_IMPLEMENTATION_ADDRESS
239-
}
240-
const randomNonceConfig = {
241-
...config,
242-
nonceMechanism: NonceMechanism.Random
243-
}
244-
const countingNonceConfig = {
245-
...config,
246-
nonceMechanism: NonceMechanism.Counting
247-
}
248-
const foreignNonceConfig = {
249-
...config,
250-
nonceMechanism: 'foreign'
251-
}
252-
253238
beforeEach(() => init())
254239

255240
it('should generate nonce with random mechanism', async () => {
256241
const randomIdentityWallet = new IdentityWallet(
257242
fakeTLProvider,
258243
FAKE_CHAIN_ID,
259-
randomNonceConfig
244+
IDENTITY_FACTORY_ADDRESS,
245+
IDENTITY_IMPLEMENTATION_ADDRESS,
246+
NonceMechanism.Random
260247
)
261248
assert.isString(await randomIdentityWallet.getNonce())
262249
})
@@ -265,24 +252,14 @@ describe('unit', () => {
265252
const countingIdentityWallet = new IdentityWallet(
266253
fakeTLProvider,
267254
FAKE_CHAIN_ID,
268-
countingNonceConfig
255+
IDENTITY_FACTORY_ADDRESS,
256+
IDENTITY_IMPLEMENTATION_ADDRESS,
257+
NonceMechanism.Counting
269258
)
270259
const walletData = await countingIdentityWallet.create()
271260
await countingIdentityWallet.loadFrom(walletData)
272261
assert.isString(await countingIdentityWallet.getNonce())
273262
})
274-
275-
it('should fail to generate nonce with foreign mechanism', async () => {
276-
const foreignIdentityWallet = new IdentityWallet(
277-
fakeTLProvider,
278-
FAKE_CHAIN_ID,
279-
foreignNonceConfig
280-
)
281-
assert.isRejected(
282-
foreignIdentityWallet.getNonce(),
283-
'Can not generate nonce for unknown mechanism: foreign'
284-
)
285-
})
286263
})
287264
})
288265

0 commit comments

Comments
 (0)