Skip to content

Commit

Permalink
Fixing remaing type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
corbanbrook committed Feb 28, 2024
1 parent 9b42256 commit 326f476
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 37 deletions.
22 changes: 13 additions & 9 deletions test/GasEstimation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ contract('Estimate gas usage', () => {
return Number(res.gas + BigInt(txBaseCost(txData)))
}

const guestModuleData = guestModule.interface.encodeFunctionData('execute', [bundleWithDeploy(txData), 0, []])
const guestModuleData = guestModule.interface.encodeFunctionData('execute', [
await bundleWithDeploy(txData),
0,
new Uint8Array([])
])
const res = await estimate(await guestModule.getAddress(), guestModuleData).call()
return Number(res.gas + BigInt(txBaseCost(txData)))
}
Expand Down Expand Up @@ -122,10 +126,10 @@ contract('Estimate gas usage', () => {
const estimated = await estimateGasUsage(transactions, wallet, true)

const signature = await wallet.signTransactions(transactions, 0)
const executeTxData = bundleWithDeploy(
const executeTxData = await bundleWithDeploy(
wallet.mainModule.interface.encodeFunctionData('execute', [applyTxDefaults(transactions), 0, signature])
)
const realTx = await guestModule.execute(executeTxData, 0, [])
const realTx = await guestModule.execute(executeTxData, 0, new Uint8Array([]))

expect(estimated).to.approximately(await gasUsedFor(realTx), 5000)
})
Expand All @@ -145,10 +149,10 @@ contract('Estimate gas usage', () => {
const estimated = await estimateGasUsage(transactions, wallet, true)

const signature = await wallet.signTransactions(transactions, 0)
const executeTxData = bundleWithDeploy(
const executeTxData = await bundleWithDeploy(
wallet.mainModule.interface.encodeFunctionData('execute', [applyTxDefaults(transactions), 0, signature])
)
const realTx = await guestModule.execute(executeTxData, 0, [])
const realTx = await guestModule.execute(executeTxData, 0, new Uint8Array([]))

expect(estimated).to.approximately(await gasUsedFor(realTx), 5000)

Expand All @@ -173,10 +177,10 @@ contract('Estimate gas usage', () => {
const estimated = await estimateGasUsage(transactions, wallet, true)

const signature = await wallet.signTransactions(transactions, 0)
const executeTxData = bundleWithDeploy(
const executeTxData = await bundleWithDeploy(
wallet.mainModule.interface.encodeFunctionData('execute', [applyTxDefaults(transactions), 0, signature])
)
const realTx = await guestModule.execute(executeTxData, 0, [])
const realTx = await guestModule.execute(executeTxData, 0, new Uint8Array([]))

expect(estimated).to.approximately(await gasUsedFor(realTx), 5000)
})
Expand All @@ -198,10 +202,10 @@ contract('Estimate gas usage', () => {
const estimated = await estimateGasUsage(transactions, wallet, true)

const signature = await wallet.signTransactions(transactions, 0)
const executeTxData = bundleWithDeploy(
const executeTxData = await bundleWithDeploy(
wallet.mainModule.interface.encodeFunctionData('execute', [applyTxDefaults(transactions), 0, signature])
)
const realTx = await guestModule.execute(executeTxData, 0, [])
const realTx = await guestModule.execute(executeTxData, 0, new Uint8Array([]))

expect(estimated).to.approximately(await gasUsedFor(realTx), 5000)
})
Expand Down
78 changes: 50 additions & 28 deletions test/MainModule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,15 @@ contract('MainModule', (accounts: string[]) => {
throw new Error('No receipt')
}

const ev1 = receipt1.events!.find(l => l.event === 'NonceChange')
expect(ev1!.event).to.be.eql('NonceChange')
const events1 = receipt1.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
const ev1 = events1.find(ev => ev.eventName === 'NonceChange')
expect(ev1!.eventName).to.be.eql('NonceChange')
expect(ev1!.args!._space).to.equal(space.toString())
expect(ev1!.args!._newNonce).to.equal(1)

const ev2 = receipt2.events!.find(l => l.event === 'NonceChange')
expect(ev2!.event).to.be.eql('NonceChange')
const events2 = receipt2.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
const ev2 = events2.find(ev => ev.eventName === 'NonceChange')
expect(ev2!.eventName).to.be.eql('NonceChange')
expect(ev2!.args!._space).to.equal(space.toString())
expect(ev2!.args!._newNonce).to.equal(2)
})
Expand Down Expand Up @@ -471,13 +473,15 @@ contract('MainModule', (accounts: string[]) => {
throw new Error('No receipt')
}

const ev1 = receipt1.events!.find(l => l.event === 'NonceChange')
expect(ev1!.event).to.be.eql('NonceChange')
const events1 = receipt1.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
const ev1 = events1.find(ev => ev.eventName === 'NonceChange')
expect(ev1!.eventName).to.be.eql('NonceChange')
expect(ev1!.args!._space).to.equal(1)
expect(ev1!.args!._newNonce).to.equal(3)

const ev2 = receipt2.events!.find(l => l.event === 'NonceChange')
expect(ev2!.event).to.be.eql('NonceChange')
const events2 = receipt2.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
const ev2 = events2.find(ev => ev.eventName === 'NonceChange')
expect(ev2!.eventName).to.be.eql('NonceChange')
expect(ev2!.args!._space).to.equal(2)
expect(ev2!.args!._newNonce).to.equal(1)
})
Expand Down Expand Up @@ -529,7 +533,10 @@ contract('MainModule', (accounts: string[]) => {
const mock_wallet = ModuleMock.attach(wallet.address)
const tx = await mock_wallet.ping()
const receipt = await tx.wait()
expect(receipt?.events![0].event).to.equal('Pong')

const events = receipt!.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]

expect(events![0].eventName).to.equal('Pong')
})
it('Should fail to set implementation to address 0', async () => {
const transaction = {
Expand Down Expand Up @@ -1050,7 +1057,8 @@ contract('MainModule', (accounts: string[]) => {
throw new Error('No receipt')
}

const event = receipt.events!.pop()
const events = receipt.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
const event = events.pop()

const reason = ethers.AbiCoder.defaultAbiCoder().decode(['string'], '0x' + event!.args!._reason.slice(10))[0]
expect(reason).to.equal('CallReceiverMock#testCall: REVERT_FLAG')
Expand Down Expand Up @@ -1086,9 +1094,10 @@ contract('MainModule', (accounts: string[]) => {
throw new Error('No receipt')
}

const event = receipt.events!.find(l => l.event === 'TxFailed')
const events = receipt.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
const ev = events.find(ev => ev.eventName === 'TxFailed')

const reason = ethers.AbiCoder.defaultAbiCoder().decode(['string'], '0x' + event!.args!._reason.slice(10))[0]
const reason = ethers.AbiCoder.defaultAbiCoder().decode(['string'], '0x' + ev!.args!._reason.slice(10))[0]
expect(reason).to.equal('CallReceiverMock#testCall: REVERT_FLAG')

expect(await callReceiver2.lastValA()).to.equal(valA)
Expand Down Expand Up @@ -1122,8 +1131,10 @@ contract('MainModule', (accounts: string[]) => {
throw new Error('No receipt')
}

const event1 = receipt.events![1]
const event2 = receipt.events![2]
const events = receipt.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]

const event1 = events[1]
const event2 = events[2]

const reason1 = ethers.AbiCoder.defaultAbiCoder().decode(['string'], '0x' + event1.args!._reason.slice(10))[0]
const reason2 = ethers.AbiCoder.defaultAbiCoder().decode(['string'], '0x' + event2.args!._reason.slice(10))[0]
Expand Down Expand Up @@ -1160,8 +1171,10 @@ contract('MainModule', (accounts: string[]) => {
throw new Error('No receipt')
}

const event1 = receipt.events!.pop()
const event2 = receipt.events!.pop()
const events = receipt.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]

const event1 = events.pop()
const event2 = events.pop()

const reason1 = ethers.AbiCoder.defaultAbiCoder().decode(['string'], '0x' + event1!.args!._reason.slice(10))[0]
const reason2 = ethers.AbiCoder.defaultAbiCoder().decode(['string'], '0x' + event2!.args!._reason.slice(10))[0]
Expand Down Expand Up @@ -1334,11 +1347,11 @@ contract('MainModule', (accounts: string[]) => {
throw new Error('No receipt')
}

const event = receipt.events?.find(e => e.event === 'DefinedHook')
const events = receipt.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]
const event = events.find(ev => ev.eventName === 'DefineHook')
expect(event).to.not.be.undefined
const decode = event!.decode!(event!.data)
expect(decode._signature).to.equal(selector)
expect(decode._implementation).to.equal(implementation)
expect(event!.args._signature).to.equal(selector)
expect(event!.args._implementation).to.equal(implementation)
})

it('Should emit an event when removing a hook', async () => {
Expand Down Expand Up @@ -1855,9 +1868,10 @@ contract('MainModule', (accounts: string[]) => {
if (!receipt) {
throw new Error('No receipt')
}
const events = receipt.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]

const log = receipt.events!.pop()
expect(log!.event).to.be.equal('TxFailed')
const log = events.pop()
expect(log!.eventName).to.be.equal('TxFailed')
})

it('Should continue execution if optional call runs out of gas', async () => {
Expand Down Expand Up @@ -1886,9 +1900,11 @@ contract('MainModule', (accounts: string[]) => {
throw new Error('No receipt')
}

const log = receipt.events!.slice(-2)[0]
const events = receipt.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]

const log = events.slice(-2)[0]

expect(log.event).to.be.equal('TxFailed')
expect(log.eventName).to.be.equal('TxFailed')
expect(await callReceiver.lastValA()).to.equal(valA)
expect(await callReceiver.lastValB()).to.equal(valB)
})
Expand Down Expand Up @@ -1918,9 +1934,11 @@ contract('MainModule', (accounts: string[]) => {
throw new Error('No receipt')
}

const log = receipt.events!.find(l => l.event === 'CreatedContract')
const events = receipt.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]

expect(log!.event).to.equal('CreatedContract')
const log = events!.find(l => l.eventName === 'CreatedContract')

expect(log!.eventName).to.equal('CreatedContract')

const deployed = CallReceiverMock.attach(log!.args!._contract)
await deployed.testCall(12345, '0x552299')
Expand All @@ -1946,7 +1964,9 @@ contract('MainModule', (accounts: string[]) => {
throw new Error('No receipt')
}

const log = receipt.events!.find(l => l.event === 'CreatedContract')
const events = receipt.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]

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

expect(await hethers.provider.getBalance(log!.args!._contract)).to.equal(99)
})
Expand All @@ -1967,7 +1987,9 @@ contract('MainModule', (accounts: string[]) => {
throw new Error('No receipt')
}

const log = receipt.events!.find(l => l.event === 'TxExecuted')!
const events = receipt.logs.filter(log => log instanceof ethers.EventLog) as ethers.EventLog[]

const log = events!.find(l => l.eventName === 'TxExecuted')!

expect(log.topics.length).to.equal(2)
expect(log.topics[1]).to.be.equal(txHash)
Expand Down

0 comments on commit 326f476

Please sign in to comment.