This repository has been archived by the owner on Feb 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
uses an empty array to represent a null filter parameter (#228)
* uses an empty array to represent a null filter parameter * Removes unnecesary imports * adds filters unit tests
- Loading branch information
1 parent
fa276fa
commit 5c646cd
Showing
6 changed files
with
160 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
# OS-specific files | ||
.DS_Store | ||
|
||
# Files and directories created by pub | ||
.packages | ||
.pub/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import 'package:test/test.dart'; | ||
import 'package:web3dart/web3dart.dart'; | ||
|
||
import '../mock_client.dart'; | ||
|
||
void main() { | ||
const alice = | ||
'0x000000000000000000000000Dd611f2b2CaF539aC9e12CF84C09CB9bf81CA37F'; | ||
const bob = | ||
'0x0000000000000000000000006c87E1a114C3379BEc929f6356c5263d62542C13'; | ||
const contract = '0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d'; | ||
|
||
final testCases = [ | ||
{ | ||
'name': 'one topic', | ||
'input': [ | ||
[alice] | ||
], | ||
'expected': [ | ||
[alice] | ||
] | ||
}, | ||
{ | ||
'name': 'two topics one item', | ||
'input': [ | ||
[alice, bob] | ||
], | ||
'expected': [ | ||
[alice, bob] | ||
] | ||
}, | ||
{ | ||
'name': 'two topics two items', | ||
'input': [ | ||
[alice], | ||
[bob] | ||
], | ||
'expected': [ | ||
[alice], | ||
[bob] | ||
] | ||
}, | ||
{ | ||
'name': 'two topics first null', | ||
'input': [ | ||
[], | ||
[bob] | ||
], | ||
'expected': [ | ||
null, | ||
[bob] | ||
] | ||
}, | ||
{ | ||
'name': 'three topics first null', | ||
'input': [ | ||
[], | ||
[alice], | ||
[bob] | ||
], | ||
'expected': [ | ||
null, | ||
[alice], | ||
[bob] | ||
] | ||
}, | ||
{ | ||
'name': 'three topics second null', | ||
'input': [ | ||
[alice], | ||
[], | ||
[bob] | ||
], | ||
'expected': [ | ||
[alice], | ||
null, | ||
[bob] | ||
] | ||
} | ||
]; | ||
|
||
Future _runFilterTest(input, expected) async { | ||
final client = MockClient(expectAsync2((method, params) { | ||
expect(method, 'eth_getLogs'); | ||
|
||
// verify that the topics are sent to eth_getLogs in the correct format | ||
final actual = ((params as List)[0])['topics']; | ||
expect(actual, expected); | ||
|
||
// return a valid response from eth_getLogs | ||
return [ | ||
{'address': contract} | ||
]; | ||
})); | ||
|
||
final web3 = Web3Client('', client); | ||
addTearDown(web3.dispose); | ||
|
||
// Dart typing will not allow an empty list to be added so when an empty | ||
// list is encountered, a list containing a single string is added and then | ||
// the single string in that list is removed. | ||
// The type is required to ensure `topics` is forced to List<List<String>> | ||
|
||
// ignore: omit_local_variable_types | ||
final List<List<String>> topics = []; | ||
input.forEach((element) { | ||
if (element.length == 0) { | ||
topics.add(['dummy string element']); | ||
topics.last.remove('dummy string element'); | ||
} else { | ||
topics.add(element as List<String>); | ||
} | ||
}); | ||
|
||
final filter = FilterOptions( | ||
fromBlock: const BlockNum.genesis(), | ||
toBlock: const BlockNum.current(), | ||
address: EthereumAddress.fromHex(contract), | ||
topics: topics); | ||
|
||
await web3.getLogs(filter); | ||
} | ||
|
||
// test each test case in the list of test cases | ||
for (final testCase in testCases) { | ||
test('filters test with ${testCase['name']}', () async { | ||
await _runFilterTest(testCase['input'], testCase['expected']); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters