-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBloom.test.mo
65 lines (60 loc) · 1.88 KB
/
Bloom.test.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import Debug "mo:base/Debug";
import Nat8 "mo:base/Nat8";
import M "mo:matchers/Matchers";
import { run; suite; testLazy } "mo:matchers/Suite";
import T "mo:matchers/Testable";
import Hex "mo:merkle-patricia-trie/util/Hex";
import { keccak } "mo:merkle-patricia-trie/util/Keccak";
import Bloom "../src/Bloom";
import Converter "../src/Converter";
import Utils "../src/Utils";
import { expected1_receipt; input1_receipt } "TestData";
import { textToKeccakBytes } "TestUtils";
run(
suite(
"Bloom",
[
testLazy(
"create",
func() : [Nat8] {
let bytes = switch (Hex.toArray(input1_receipt.proof[input1_receipt.proof.size() -1][1])) {
case (#err(error)) {
Debug.print(debug_show (error));
return [];
};
case (#ok(value)) value;
};
let decoded = switch (Converter.decodeReceipt(bytes)) {
case (#err(error)) {
Debug.print(debug_show (error));
return [];
};
case (#ok(value)) value;
};
Bloom.create(decoded.logs);
},
M.equals(T.array(T.nat8Testable, Hex.toArrayUnsafe(expected1_receipt.logsBloom))),
),
testLazy(
"test",
func() : Bool {
let bloom = Hex.toArrayUnsafe(expected1_receipt.logsBloom);
M.assertThat(
Bloom.test(bloom, textToKeccakBytes(expected1_receipt.logs[0].topics[0])),
M.equals(T.bool(true)),
);
M.assertThat(
Bloom.test(bloom, Utils.padBytes(Hex.toArrayUnsafe(expected1_receipt.logs[0].topics[1]), 32)),
M.equals(T.bool(true)),
);
M.assertThat(
Bloom.test(bloom, Hex.toArrayUnsafe(expected1_receipt.logs[0].topics[1])),
M.equals(T.bool(false)),
);
true;
},
M.anything(),
),
],
)
);