Skip to content

Commit

Permalink
Merge pull request #75 from twostack/network-address-fix
Browse files Browse the repository at this point in the history
Bugfix: Override of network type fails when deriving address
  • Loading branch information
stephanfeb authored Oct 13, 2023
2 parents bb5662c + 1fc67cc commit b43c85e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/src/privatekey.dart
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ class SVPrivateKey {
/// Convenience method that jumps through the hoops of generating and [Address] from this
/// Private Key's corresponding [SVPublicKey].
Address toAddress({NetworkType networkType = NetworkType.MAIN}) {
//FIXME: set network type to default parameter unless explicitly specified ?
return _svPublicKey!.toAddress(_networkType);
return _svPublicKey!.toAddress(networkType);
}

Uint8List _seed() {
Expand Down
17 changes: 16 additions & 1 deletion test/privatekey_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,25 @@ main(){

test('should output this known testnet address correctly', () {
var privkey = SVPrivateKey.fromWIF('cR4qogdN9UxLZJXCNFNwDRRZNeLRWuds9TTSuLNweFVjiaE4gPaq');
var address = privkey.toAddress();
var address = privkey.toAddress(networkType: NetworkType.TEST);
expect(address.toString(), equals('mtX8nPZZdJ8d3QNLRJ1oJTiEi26Sj6LQXS'));
});

test('should honor the network type setting for toAddress() ', () {

//take a wif from mainnet
SVPrivateKey privateKey = SVPrivateKey.fromWIF('L3T1s1TYP9oyhHpXgkyLoJFGniEgkv2Jhi138d7R2yJ9F4QdDU2m');
Address testnetAddress = privateKey.toAddress(networkType: NetworkType.TEST);

//expect a testnet address
expect(testnetAddress.toString(), equals('mpcsB4yVbWGGDLsx5R3Gi8uLvwDJDLAVcv'));

//expect a mainnet address
Address mainnetAddress= privateKey.toAddress(networkType: NetworkType.MAIN);
expect(mainnetAddress.toString(), equals('1A6ut1tWnUq1SEQLMr4ttDh24wcbJ5o9TT'));

});

test('should parse this compressed testnet address correctly', () {
var wifLivenet = 'L2Gkw3kKJ6N24QcDuH4XDqt9cTqsKTVNDGz1CRZhk9cq4auDUbJy';
var privkey = SVPrivateKey.fromWIF(wifLivenet);
Expand Down

0 comments on commit b43c85e

Please sign in to comment.