dev
dart 45 lines 1.29 KB
Raw
1 import "dart:typed_data";
2
3 import "package:cw_evm/utils/evm_chain_formatter.dart";
4 import "package:cw_evm/utils/rlp_decode.dart";
5 import "package:flutter_test/flutter_test.dart";
6 import "package:web3dart/crypto.dart";
7 import "package:web3dart/src/utils/rlp.dart" as rlp;
8
9 void main() {
10 group("EVMChainFormatter", () {
11 group("truncateDecimals", () {
12 test("no decimals", () => expect(EVMChainFormatter.truncateDecimals("5", 6), "5"));
13 test("less than max decimals",
14 () => expect(EVMChainFormatter.truncateDecimals("5.00001", 6), "5.00001"));
15 test("max decimals",
16 () => expect(EVMChainFormatter.truncateDecimals("5.000001", 6), "5.000001"));
17 test("more than max decimals",
18 () => expect(EVMChainFormatter.truncateDecimals("5.0000001", 6), "5.000000"));
19 });
20 });
21 group("rlp decode", () {
22 test("0x05", () => expect(decode(hexToBytes("0x05")), [5]));
23 test(
24 "0xc88363617483646f67",
25 () => expect(
26 decode(hexToBytes("0xc88363617483646f67")),
27 [
28 [99, 97, 116],
29 [100, 111, 103]
30 ],
31 ),
32 );
33
34 test(
35 "cat dog",
36 () => expect(
37 decode(Uint8List.fromList(rlp.encode(["cat", "dog"]))),
38 [
39 [99, 97, 116],
40 [100, 111, 103]
41 ],
42 ),
43 );
44 });
45 }