Skip to content

Commit eb7f9a7

Browse files
committed
fix: gen hd wallet bugs
1 parent 14efc8f commit eb7f9a7

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

packages/web3/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [1.0.5]
2+
3+
- fix: fix generate hd wallet bugs.
4+
- unit tests: add test cases;
5+
16
## [1.0.4]
27

38
- fix getBalance bugs, log and throw socket io error.

packages/web3/lib/src/chain/ethereum/eth.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class EthWallet {
6969
var publicAddress = (await genPublicAddress(privateKey)).hex.toLowerCase();
7070

7171
return HDWallet(
72-
mnemonic: genMnemonic(),
72+
mnemonic: mnemonic,
7373
privateKey: privateKey,
7474
publicAddress: publicAddress,
7575
);

packages/web3/lib/src/model/token.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ class TokenOption {
3030
this.isErc721,
3131
this.decimals,
3232
});
33+
34+
@override
35+
String toString() {
36+
return 'TokenOption{address: $address, addressTest: $addressTest, symbol: $symbol, logo: $logo, name: $name, isErc20: $isErc20, isErc721: $isErc721, decimals: $decimals}';
37+
}
3338
}

packages/web3/test/web3_test.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import 'package:flutter_test/flutter_test.dart';
22

3+
import '../lib/web3.dart';
4+
35
void main() {
6+
const rpcUrl = 'https://kovan.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161';
7+
var client = EthWallet(url: rpcUrl);
8+
49
test('adds one to input values', () {
510
// final calculator = Calculator();
611
// expect(calculator.addOne(2), 3);
@@ -10,4 +15,38 @@ void main() {
1015
});
1116

1217
test('dotEnv test', () {});
18+
19+
test('web3 test - gen hd wallet', () async {
20+
var hd = await client.genHDWallet();
21+
print('hd wallet: $hd');
22+
});
23+
24+
test('web3 test - get balance', () async {
25+
var address = '0x9fe1901f3bb6cd21dca275f5e746409bd4ae8861';
26+
var result = await client.getBalance(address: address);
27+
print('get balance : $result');
28+
});
29+
30+
test('web3 test - diff privateKey', () async {
31+
/// HDWallet{
32+
/// mnemonic: around fall gather unusual load wish cream dust reason face squirrel toe,
33+
/// privateKey: 6e02997235fbadea7161e38cd8a8c2a0cca7c50e6d218b38763935f2472f7486,
34+
/// publicAddress: 0xe88b8b1f3f6f457f68b6b0eea8970da4e076006c}
35+
///
36+
var mnemonic = 'around fall gather unusual load wish cream dust reason face squirrel toe';
37+
var privateKey = '6e02997235fbadea7161e38cd8a8c2a0cca7c50e6d218b38763935f2472f7486';
38+
var publicAddress = '0xe88b8b1f3f6f457f68b6b0eea8970da4e076006c';
39+
40+
/// gen:
41+
var retPrivateKey = client.privateKeyFromMnemonic(mnemonic);
42+
var retAddress1 = await client.genPublicAddress(privateKey);
43+
var retAddress2 = await client.genPublicAddress(retPrivateKey);
44+
45+
assert(retPrivateKey == privateKey);
46+
assert(publicAddress == retAddress1.toString());
47+
assert(publicAddress == retAddress2.toString());
48+
49+
print('gen privateKey $retPrivateKey');
50+
print('gen address: $retAddress1, $retAddress2');
51+
});
1352
}

0 commit comments

Comments
 (0)