Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BCN, BWS, CWC, Bitcore-libs] Add named testnets to as networks #3714

Merged
merged 28 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
defd489
enable aliases in bitcore api
escottalexander Mar 14, 2024
788a6dd
add named testnets to bws
escottalexander Mar 20, 2024
d102e85
bitcore-lib named testnets
escottalexander Mar 20, 2024
0bd8e43
correct aliases
escottalexander Mar 20, 2024
e2341a5
clean up derivation paths
escottalexander Mar 20, 2024
fa1f37e
add sepolia and holesky, remove deprecated testnets
escottalexander Mar 20, 2024
1bdc11d
remove 'testnet' and use aliases
escottalexander Mar 22, 2024
4327f97
lint
escottalexander Mar 22, 2024
aa59837
check for aliased name
escottalexander Mar 28, 2024
4ee5e0c
bws named testnet migration script
escottalexander Mar 28, 2024
ecb7c5e
bcn named testnet migration script
escottalexander Mar 29, 2024
2e7ab55
add type
escottalexander Apr 1, 2024
a55036a
use correct network in raw tx
escottalexander Apr 1, 2024
a8410e7
add tests and change to expect testnet3
escottalexander Apr 1, 2024
e589b4e
change to address from correct derivation path
escottalexander Apr 1, 2024
b010f9f
change case
escottalexander Apr 1, 2024
b9668da
updates to how we handle testnet variants
escottalexander Apr 3, 2024
e397014
remove top level chain and network
escottalexander Apr 4, 2024
3d5474d
merge eth and matic route into evm route
escottalexander Apr 4, 2024
7577ccf
feedback
escottalexander Apr 4, 2024
3aa21f4
push notification suggestions
escottalexander Apr 4, 2024
bc81877
testnet variant tests
escottalexander Apr 4, 2024
73156aa
change expected network
escottalexander Apr 4, 2024
9be6ca2
dont check for testnet port
escottalexander Apr 4, 2024
46dab62
feedback
escottalexander Apr 4, 2024
e26a411
address feedback
escottalexander Apr 5, 2024
26032de
compare network type
escottalexander Apr 5, 2024
8e6690c
check for type
escottalexander Apr 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/bitcore-client/test/unit/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ describe('Wallet', function() {
feeTarget: 2
});
params.gasPrice.should.equal(26550000000);
expect(newTx).to.equal('0xed8085062e80d98083030d40947ee308b49e36ab516cd0186b3a47cfd31d2499a1880de0b6b3a764000080058080');
expect(newTx).to.equal('0xf08085062e80d98083030d40947ee308b49e36ab516cd0186b3a47cfd31d2499a1880de0b6b3a76400008083aa36a78080');
});

it('should bump the fee of a transaction with feeRate', async function() {
Expand All @@ -195,7 +195,7 @@ describe('Wallet', function() {
feeRate: 300
});
params.gasPrice.should.equal(CWC.Web3.utils.toWei('300', 'gwei'));
expect(newTx).to.equal('0xed808545d964b80083030d40947ee308b49e36ab516cd0186b3a47cfd31d2499a1880de0b6b3a764000080058080');
expect(newTx).to.equal('0xf0808545d964b80083030d40947ee308b49e36ab516cd0186b3a47cfd31d2499a1880de0b6b3a76400008083aa36a78080');
});
});
});
Expand Down
83 changes: 76 additions & 7 deletions packages/bitcore-lib-cash/lib/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ function get(arg, keys) {
}
}

/**
* @function
* @member Networks#is
* Returns true if the string is the network name or alias
* @param {string} str - A string to check
* @return boolean
*/
function is(str) {
return this.name == str || this.alias == str;
}

/***
* Derives an array from the given prefix to be used in the computation
* of the address' checksum.
Expand Down Expand Up @@ -89,6 +100,7 @@ function addNetwork(data) {
JSUtil.defineImmutable(network, {
name: data.name,
alias: data.alias,
is: data.is,
pubkeyhash: data.pubkeyhash,
privatekey: data.privatekey,
scripthash: data.scripthash,
Expand Down Expand Up @@ -184,6 +196,7 @@ var dnsSeeds = [
var liveNetwork = {
name: 'livenet',
alias: 'mainnet',
is,
prefix: 'bitcoincash',
pubkeyhash: 28,
privatekey: 0x80,
Expand All @@ -195,8 +208,10 @@ var liveNetwork = {
dnsSeeds: dnsSeeds
};

var testNetwork = {
name: 'testnet',
var testnet3 = {
name: 'testnet3',
alias: 'testnet',
is,
prefix: 'bchtest',
pubkeyhash: 0x6f,
privatekey: 0xef,
Expand All @@ -208,8 +223,51 @@ var testNetwork = {
dnsSeeds: dnsSeeds
};

var testnet4 = {
name: 'testnet4',
is,
prefix: 'bchtest',
pubkeyhash: 0x6f,
privatekey: 0xef,
scripthash: 0xc4,
xpubkey: 0x043587cf,
xprivkey: 0x04358394,
networkMagic: 0xe2b7daaf,
port: 28333,
dnsSeeds: dnsSeeds
};

var scalenet = {
name: 'scalenet',
is,
prefix: 'bchtest',
pubkeyhash: 0x6f,
privatekey: 0xef,
scripthash: 0xc4,
xpubkey: 0x043587cf,
xprivkey: 0x04358394,
networkMagic: 0xc3afe1a2,
port: 38333,
dnsSeeds: dnsSeeds
};

var chipnet = {
name: 'chipnet',
is,
prefix: 'bchtest',
pubkeyhash: 0x6f,
privatekey: 0xef,
scripthash: 0xc4,
xpubkey: 0x043587cf,
xprivkey: 0x04358394,
networkMagic: 0xe2b7daaf,
port: 48333,
dnsSeeds: dnsSeeds
};

var regtestNetwork = {
name: 'regtest',
is,
prefix: 'bchreg',
pubkeyhash: 0x6f,
privatekey: 0xef,
Expand All @@ -231,13 +289,19 @@ var regtestNetwork = {
// Add configurable values for testnet/regtest


addNetwork(testNetwork);
addNetwork(testnet3);
addNetwork(testnet4);
addNetwork(scalenet);
addNetwork(chipnet);
addNetwork(regtestNetwork);
addNetwork(liveNetwork);

var livenet = get('livenet');
var regtest = get('regtest');
var testnet = get('testnet');
var testnet3 = get('testnet3');
var testnet4 = get('testnet4');
var scalenet = get('scalenet');
var chipnet = get('chipnet');

/**
* @function
Expand All @@ -246,7 +310,7 @@ var testnet = get('testnet');
* Will enable regtest features for testnet
*/
function enableRegtest() {
testnet.regtestEnabled = true;
testnet3.regtestEnabled = true;
}

/**
Expand All @@ -256,7 +320,7 @@ function enableRegtest() {
* Will disable regtest features for testnet
*/
function disableRegtest() {
testnet.regtestEnabled = false;
testnet3.regtestEnabled = false;
}

/**
Expand All @@ -268,9 +332,14 @@ module.exports = {
defaultNetwork: livenet,
livenet: livenet,
mainnet: livenet,
testnet: testnet,
testnet: testnet3,
testnet3: testnet3,
testnet4: testnet4,
scalenet: scalenet,
chipnet: chipnet,
regtest: regtest,
get: get,
is: is,
escottalexander marked this conversation as resolved.
Show resolved Hide resolved
enableRegtest: enableRegtest,
disableRegtest: disableRegtest
};
8 changes: 7 additions & 1 deletion packages/bitcore-lib-cash/test/hdprivatekey.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ describe('HDPrivate key interface', function() {
});

it('should make a new private key from random for testnet', function() {
var key = new HDPrivateKey('testnet3');
should.exist(key.xprivkey);
key.network.name.should.equal('testnet3');
});

it('should make a new private key from random for testnet with name "testnet"', function() {
var key = new HDPrivateKey('testnet');
should.exist(key.xprivkey);
key.network.name.should.equal('testnet');
key.network.name.should.equal('testnet3');
});

it('should not be able to change read-only properties', function() {
Expand Down
8 changes: 6 additions & 2 deletions packages/bitcore-lib-cash/test/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ describe('Networks', function() {
});

it('should have testnet network', function() {
expect(networks.get('testnet').name).to.equal('testnet');
expect(networks.get('testnet3').name).to.equal('testnet3');
});

it('should get testnet network with name "testnet"', function() {
expect(networks.get('testnet').name).to.equal('testnet3');
});

it('should have livenet network', function() {
Expand Down Expand Up @@ -143,7 +147,7 @@ describe('Networks', function() {
});

it('network object should be immutable', function() {
expect(networks.testnet.name).to.equal('testnet')
expect(networks.testnet.name).to.equal('testnet3')
var fn = function() { networks.testnet.name = 'livenet' }
expect(fn).to.throw(TypeError)
});
Expand Down
2 changes: 1 addition & 1 deletion packages/bitcore-lib-cash/test/privatekey.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ describe('PrivateKey', function() {
it('should output known testnet address for console', function() {
var privkey = PrivateKey.fromWIF('cR4qogdN9UxLZJXCNFNwDRRZNeLRWuds9TTSuLNweFVjiaE4gPaq');
privkey.inspect().should.equal(
'<PrivateKey: 67fd2209ce4a95f6f1d421ab3fbea47ada13df11b73b30c4d9a9f78cc80651ac, network: testnet>'
'<PrivateKey: 67fd2209ce4a95f6f1d421ab3fbea47ada13df11b73b30c4d9a9f78cc80651ac, network: testnet3>'
);
});

Expand Down
17 changes: 17 additions & 0 deletions packages/bitcore-lib-doge/lib/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ function get(arg, keys) {
return networkMaps[arg];
}
}

/**
* @function
* @member Networks#is
* Returns true if the string is the network name or alias
* @param {string} str - A string to check
* @return boolean
*/
function is(str) {
return this.name == str || this.alias == str;
}

/**
* @function
* @member Networks#add
Expand All @@ -102,6 +114,7 @@ function addNetwork(data) {
JSUtil.defineImmutable(network, {
name: data.name,
alias: data.alias,
is: data.is,
pubkeyhash: data.pubkeyhash,
privatekey: data.privatekey,
scripthash: data.scripthash,
Expand Down Expand Up @@ -138,6 +151,7 @@ function addNetwork(data) {
addNetwork({
name: 'livenet',
alias: 'mainnet',
is,
pubkeyhash: 0x1e,
privatekey: 0x9e,
scripthash: 0x16,
Expand Down Expand Up @@ -167,6 +181,7 @@ var livenet = get('livenet');
addNetwork({
name: 'testnet',
alias: 'test',
is,
pubkeyhash: 0x71,
privatekey: 0xf1,
scripthash: 0xc4,
Expand All @@ -189,6 +204,7 @@ var testnet = get('testnet');
addNetwork({
name: 'regtest',
alias: 'dev',
is,
pubkeyhash: 0x6f,
privatekey: 0xef,
scripthash: 0xc4,
Expand Down Expand Up @@ -234,6 +250,7 @@ module.exports = {
testnet: testnet,
regtest: regtest,
get: get,
is: is,
escottalexander marked this conversation as resolved.
Show resolved Hide resolved
enableRegtest: enableRegtest,
disableRegtest: disableRegtest
};
16 changes: 16 additions & 0 deletions packages/bitcore-lib-ltc/lib/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,17 @@ function get(arg, keys) {
}
}

/**
* @function
* @member Networks#is
* Returns true if the string is the network name or alias
* @param {string} str - A string to check
* @return boolean
*/
function is(str) {
return this.name == str || this.alias == str;
}

/**
* @function
* @member Networks#add
Expand All @@ -76,6 +87,7 @@ function addNetwork(data) {
JSUtil.defineImmutable(network, {
name: data.name,
alias: data.alias,
is,
pubkeyhash: data.pubkeyhash,
privatekey: data.privatekey,
scripthash: data.scripthash,
Expand Down Expand Up @@ -157,6 +169,7 @@ function removeNetwork(network) {
addNetwork({
name: 'livenet',
alias: 'mainnet',
is,
pubkeyhash: 0x30, // 48
privatekey: 0xb0, // 176
scripthash: 0x32, // 50
Expand Down Expand Up @@ -185,6 +198,7 @@ var livenet = get('livenet');
addNetwork({
name: 'testnet',
alias: 'test',
is,
pubkeyhash: 0x6f, // 111
privatekey: 0xef, // 239
scripthash: 0x3a, // 58
Expand All @@ -209,6 +223,7 @@ var testnet = get('testnet');
addNetwork({
name: 'regtest',
alias: 'dev',
is,
pubkeyhash: 0x6f, // 111
privatekey: 0xef, // 239
scripthash: 0x3a, // 58
Expand Down Expand Up @@ -259,6 +274,7 @@ module.exports = {
testnet: testnet,
regtest: regtest,
get: get,
is: is,
escottalexander marked this conversation as resolved.
Show resolved Hide resolved
enableRegtest: enableRegtest,
disableRegtest: disableRegtest
};