Skip to content

Commit 3de3781

Browse files
committed
Fixing remaining tests
1 parent 7f868b0 commit 3de3781

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

test/MainModule.spec.ts

+25-26
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ethers } from 'ethers'
22
import { ethers as hethers } from 'hardhat'
33

4-
import { bytes32toAddress, getChainId, expect, expectToBeRejected, randomHex } from './utils'
4+
import { bytes32toAddress, getChainId, expect, expectToBeRejected, randomHex, getSigHash } from './utils'
55

66
import {
77
CallReceiverMock,
@@ -361,14 +361,14 @@ contract('MainModule', (accounts: string[]) => {
361361
const events1 = receipt1.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
362362
const ev1 = events1.find(ev => ev.eventName === 'NonceChange')
363363
expect(ev1!.eventName).to.be.eql('NonceChange')
364-
expect(ev1!.args._space).to.equal(0)
365-
expect(ev1!.args._newNonce).to.equal(1)
364+
expect(ev1!.args._space).to.equal(0n)
365+
expect(ev1!.args._newNonce).to.equal(1n)
366366

367367
const events2 = receipt2.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
368368
const ev2 = events2.find(ev => ev.eventName === 'NonceChange')
369369
expect(ev2!.eventName).to.be.eql('NonceChange')
370-
expect(ev1!.args._space).to.equal(0)
371-
expect(ev2!.args._newNonce).to.equal(2)
370+
expect(ev1!.args._space).to.equal(0n)
371+
expect(ev2!.args._newNonce).to.equal(2n)
372372
})
373373

374374
it('Should fail if nonce did not change', async () => {
@@ -402,14 +402,14 @@ contract('MainModule', (accounts: string[]) => {
402402
const events1 = receipt1.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
403403
const ev1 = events1.find(ev => ev.eventName === 'NonceChange')
404404
expect(ev1!.eventName).to.be.eql('NonceChange')
405-
expect(ev1!.args!._space).to.equal(space.toString())
406-
expect(ev1!.args!._newNonce).to.equal(1)
405+
expect(ev1!.args!._space).to.equal(space)
406+
expect(ev1!.args!._newNonce).to.equal(1n)
407407

408408
const events2 = receipt2.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
409409
const ev2 = events2.find(ev => ev.eventName === 'NonceChange')
410410
expect(ev2!.eventName).to.be.eql('NonceChange')
411-
expect(ev2!.args!._space).to.equal(space.toString())
412-
expect(ev2!.args!._newNonce).to.equal(2)
411+
expect(ev2!.args!._space).to.equal(space)
412+
expect(ev2!.args!._newNonce).to.equal(2n)
413413
})
414414

415415
it('Should accept next nonce', async () => {
@@ -440,7 +440,7 @@ contract('MainModule', (accounts: string[]) => {
440440
await wallet.sendTransactions([{}], encodeNonce(space, 0))
441441

442442
const storageValue = await hethers.provider.getStorage(wallet.address, storageKey)
443-
expect(BigInt(storageValue)).to.equal(1)
443+
expect(BigInt(storageValue)).to.equal(1n)
444444
})
445445
})
446446
})
@@ -477,14 +477,14 @@ contract('MainModule', (accounts: string[]) => {
477477
const events1 = receipt1.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
478478
const ev1 = events1.find(ev => ev.eventName === 'NonceChange')
479479
expect(ev1!.eventName).to.be.eql('NonceChange')
480-
expect(ev1!.args!._space).to.equal(1)
481-
expect(ev1!.args!._newNonce).to.equal(3)
480+
expect(ev1!.args!._space).to.equal(1n)
481+
expect(ev1!.args!._newNonce).to.equal(3n)
482482

483483
const events2 = receipt2.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
484484
const ev2 = events2.find(ev => ev.eventName === 'NonceChange')
485485
expect(ev2!.eventName).to.be.eql('NonceChange')
486-
expect(ev2!.args!._space).to.equal(2)
487-
expect(ev2!.args!._newNonce).to.equal(1)
486+
expect(ev2!.args!._space).to.equal(2n)
487+
expect(ev2!.args!._newNonce).to.equal(1n)
488488
})
489489

490490
it('Should not accept nonce of different space', async () => {
@@ -1248,9 +1248,8 @@ contract('MainModule', (accounts: string[]) => {
12481248

12491249
before(async () => {
12501250
hookMock = await HookMock.deploy()
1251-
//hookSelector = hookMock.interface.getSighash('onHookMockCall')
12521251
const fragment = hookMock.interface.getFunction('onHookMockCall')
1253-
hookSelector = ethers.dataSlice(ethers.id(fragment.format('full')), 0, 4)
1252+
hookSelector = getSigHash(fragment)
12541253
})
12551254

12561255
it('Should return zero if hook is not registered', async () => {
@@ -1351,7 +1350,7 @@ contract('MainModule', (accounts: string[]) => {
13511350
}
13521351

13531352
const events = receipt.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
1354-
const event = events.find(ev => ev.eventName === 'DefineHook')
1353+
const event = events.find(ev => ev.eventName === 'DefinedHook')
13551354
expect(event).to.not.be.undefined
13561355
expect(event!.args._signature).to.equal(selector)
13571356
expect(event!.args._implementation).to.equal(implementation)
@@ -1380,7 +1379,7 @@ contract('MainModule', (accounts: string[]) => {
13801379
}
13811380

13821381
const events = receipt.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
1383-
const event = events.find(ev => ev.eventName === 'DefineHook')
1382+
const event = events.find(ev => ev.eventName === 'DefinedHook')
13841383
expect(event).to.not.be.undefined
13851384
expect(event?.args._signature).to.equal(selector)
13861385
expect(event?.args._implementation).to.equal(ethers.ZeroAddress)
@@ -1808,7 +1807,7 @@ contract('MainModule', (accounts: string[]) => {
18081807
throw new Error('No receipt')
18091808
}
18101809

1811-
const reported = BigInt(receipt.logs.slice(-2)[0].data)
1810+
const reported = Number(BigInt(receipt.logs.slice(-2)[0].data))
18121811
expect(reported).to.be.below(gas)
18131812
})
18141813

@@ -1835,8 +1834,8 @@ contract('MainModule', (accounts: string[]) => {
18351834
throw new Error('No receipt')
18361835
}
18371836

1838-
const reportedB = BigInt(receipt.logs.slice(-2)[0].data)
1839-
const reportedA = BigInt(receipt.logs.slice(-4)[0].data)
1837+
const reportedB = Number(BigInt(receipt.logs.slice(-2)[0].data))
1838+
const reportedA = Number(BigInt(receipt.logs.slice(-4)[0].data))
18401839

18411840
expect(reportedA).to.be.below(gasA)
18421841
expect(reportedB).to.be.below(gasB)
@@ -1880,7 +1879,7 @@ contract('MainModule', (accounts: string[]) => {
18801879
it('Should continue execution if optional call runs out of gas', async () => {
18811880
const gas = 10000
18821881

1883-
const valA = 9512358833
1882+
const valA = 9512358833n
18841883
const valB = randomHex(1600)
18851884

18861885
const transactions = [
@@ -1946,7 +1945,7 @@ contract('MainModule', (accounts: string[]) => {
19461945
const deployed = CallReceiverMock.attach(log!.args!._contract)
19471946
await deployed.testCall(12345, '0x552299')
19481947

1949-
expect(await deployed.lastValA()).to.equal(12345)
1948+
expect(await deployed.lastValA()).to.equal(12345n)
19501949
expect(await deployed.lastValB()).to.equal('0x552299')
19511950
})
19521951

@@ -1972,7 +1971,7 @@ contract('MainModule', (accounts: string[]) => {
19721971

19731972
const log = events!.find(l => l.eventName === 'CreatedContract')
19741973

1975-
expect(await hethers.provider.getBalance(log!.args!._contract)).to.equal(99)
1974+
expect(await hethers.provider.getBalance(log!.args!._contract)).to.equal(99n)
19761975
})
19771976

19781977
it('Should fail to create a contract from non-self', async () => {
@@ -2048,8 +2047,8 @@ contract('MainModule', (accounts: string[]) => {
20482047

20492048
await wallet.sendTransactions(transaction)
20502049

2051-
expect(await callReceiver.lastValA()).to.equal(11)
2052-
expect(await callReceiver2.lastValA()).to.equal(12)
2050+
expect(await callReceiver.lastValA()).to.equal(11n)
2051+
expect(await callReceiver2.lastValA()).to.equal(12n)
20532052

20542053
expect(await callReceiver.lastValB()).to.equal(expected1)
20552054
expect(await callReceiver2.lastValB()).to.equal(expected2)

test/utils/index.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,12 @@ function xor(a: any, b: any) {
107107

108108
export function interfaceIdOf(int: ethers.Interface): string {
109109
const signatures: string[] = []
110-
int.forEachFunction(f => {
111-
const sighash = ethers.dataSlice(ethers.id(f.format('sighash')), 0, 4)
112-
signatures.push(sighash)
110+
int.forEachFunction(fragment => {
111+
signatures.push(getSigHash(fragment))
113112
})
114113
return signatures.reduce((p, c) => xor(p, c))
115114
}
115+
116+
export function getSigHash(fragment: ethers.FunctionFragment): string {
117+
return ethers.dataSlice(ethers.id(fragment.format('sighash')), 0, 4)
118+
}

0 commit comments

Comments
 (0)