Skip to content

Commit 17cb789

Browse files
yann300Aniket-Engg
authored andcommitted
fix_logs
1 parent 4dd3f34 commit 17cb789

File tree

3 files changed

+97
-5
lines changed

3 files changed

+97
-5
lines changed

apps/remix-ide-e2e/src/tests/terminal.test.ts

Lines changed: 69 additions & 0 deletions
Large diffs are not rendered by default.

libs/remix-lib/src/execution/logsManager.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,21 @@ export class LogsManager {
5252
}
5353

5454
eventMatchesFilter (changeEvent, queryType, queryFilter) {
55-
if (queryFilter.topics.filter((logTopic) => changeEvent.log.topics.indexOf(logTopic) >= 0).length === 0) return false
55+
// topics should match
56+
let noMatch = false
57+
for (let i = 0; i < queryFilter.topics.length; i++) {
58+
if (!queryFilter.topics[i]) {
59+
continue // if the topic isn't defined, we consider it a match.
60+
}
61+
if (Array.isArray(queryFilter.topics[i])) {
62+
if (queryFilter.topics[i].indexOf(changeEvent.log.topics[i]) === -1) {
63+
noMatch = true
64+
}
65+
continue
66+
}
67+
if (queryFilter.topics[i] !== changeEvent.log.topics[i]) noMatch = true
68+
}
69+
if (noMatch) return false
5670

5771
if (queryType === 'logs') {
5872
const fromBlock = parseInt(queryFilter.fromBlock || '0x0')

libs/remix-simulator/test/events.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ describe('Events', () => {
3838
address: receiptTest.contractAddress,
3939
fromBlock: 3,
4040
toBlock: 'latest',
41-
topics: ['0xdcd9c7fa0342f01013bd0bf2bec103a81936162dcebd1f0c38b1d4164c17e0fc', '0x342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a735']
41+
topics: ['0xdcd9c7fa0342f01013bd0bf2bec103a81936162dcebd1f0c38b1d4164c17e0fc']
4242
})
4343

4444
let ownerLogs = await web3.eth.getPastLogs({
4545
address: receiptOwner.contractAddress,
4646
fromBlock: 3,
4747
toBlock: 'latest',
48-
topics: ['0x342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a735', '0xdcd9c7fa0342f01013bd0bf2bec103a81936162dcebd1f0c38b1d4164c17e0fc']
48+
topics: ['0x342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a735']
4949
})
5050

5151
// this should include the event triggered by the "set" transaction call.
@@ -56,7 +56,7 @@ describe('Events', () => {
5656
address: receiptOwner.contractAddress,
5757
fromBlock: 2,
5858
toBlock: 'latest',
59-
topics: ['0x342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a735', '0xdcd9c7fa0342f01013bd0bf2bec103a81936162dcebd1f0c38b1d4164c17e0fc']
59+
topics: ['0x342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a735']
6060
})
6161
// this should include the event triggered from the ctor.
6262
assert.equal(ownerLogs.length, 2, '3) ownerLogs length should be equal to 2')
@@ -65,10 +65,19 @@ describe('Events', () => {
6565
address: receiptOwner.contractAddress,
6666
fromBlock: 1,
6767
toBlock: 2,
68-
topics: ['0x342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a735', '0xdcd9c7fa0342f01013bd0bf2bec103a81936162dcebd1f0c38b1d4164c17e0fc']
68+
topics: ['0x342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a735']
6969
})
7070
// this should only include the event triggered from the ctor.
7171
assert.equal(ownerLogs.length, 1, '4) ownerLogs length should be equal to 1')
72+
73+
ownerLogs = await web3.eth.getPastLogs({
74+
address: receiptOwner.contractAddress,
75+
fromBlock: 1,
76+
toBlock: 2,
77+
topics: [['0x342827c97908e5e2f71151c08502a66d44b6f758e3ac2f1de95f02eb95f0a735', '0xdcd9c7fa0342f01013bd0bf2bec103a81936162dcebd1f0c38b1d4164c17e0fc']]
78+
})
79+
// 0xdcd9c7fa0342f01013b is a topic from a event emitted by the other contract and should not be take into account.
80+
assert.equal(ownerLogs.length, 1, '5) ownerLogs length should be equal to 1')
7281
})
7382
})
7483
})

0 commit comments

Comments
 (0)