diff --git a/package-lock.json b/package-lock.json index ee495f6d..112f4cf7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "license": "MIT", "dependencies": { "commander": "^3.0.1", - "nunjucks": "^3.2.3", + "es5-ext": "^0.10.64", + "nunjucks": "^3.2.4", "rlp": "^2.2.7", "web3": "^1.9.0" } @@ -998,13 +999,14 @@ } }, "node_modules/es5-ext": { - "version": "0.10.62", - "resolved": "https://registry.npmmirror.com/es5-ext/-/es5-ext-0.10.62.tgz", - "integrity": "sha512-BHLqn0klhEpnOKSrzn/Xsz2UIW8j+cGmo9JLzr8BiUapV8hPL9+FliFqjwr9ngW7jWdnxv6eO+/LqyhJVqgrjA==", + "version": "0.10.64", + "resolved": "https://registry.npmmirror.com/es5-ext/-/es5-ext-0.10.64.tgz", + "integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==", "hasInstallScript": true, "dependencies": { "es6-iterator": "^2.0.3", "es6-symbol": "^3.1.3", + "esniff": "^2.0.1", "next-tick": "^1.1.0" }, "engines": { @@ -1040,6 +1042,25 @@ "resolved": "https://registry.npmmirror.com/escape-html/-/escape-html-1.0.3.tgz", "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==" }, + "node_modules/esniff": { + "version": "2.0.1", + "resolved": "https://registry.npmmirror.com/esniff/-/esniff-2.0.1.tgz", + "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==", + "dependencies": { + "d": "^1.0.1", + "es5-ext": "^0.10.62", + "event-emitter": "^0.3.5", + "type": "^2.7.2" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/esniff/node_modules/type": { + "version": "2.7.2", + "resolved": "https://registry.npmmirror.com/type/-/type-2.7.2.tgz", + "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==" + }, "node_modules/etag": { "version": "1.8.1", "resolved": "https://registry.npmmirror.com/etag/-/etag-1.8.1.tgz", @@ -1128,6 +1149,15 @@ "resolved": "https://registry.npmmirror.com/bn.js/-/bn.js-4.11.6.tgz", "integrity": "sha512-XWwnNNFCuuSQ0m3r3C4LE3EiORltHd9M05pq6FOlVeiophzRbMo50Sbz1ehl8K3Z+jw9+vmgnXefY1hz8X+2wA==" }, + "node_modules/event-emitter": { + "version": "0.3.5", + "resolved": "https://registry.npmmirror.com/event-emitter/-/event-emitter-0.3.5.tgz", + "integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==", + "dependencies": { + "d": "1", + "es5-ext": "~0.10.14" + } + }, "node_modules/evp_bytestokey": { "version": "1.0.3", "resolved": "https://registry.npmmirror.com/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz", @@ -1995,9 +2025,9 @@ "integrity": "sha512-XWwnNNFCuuSQ0m3r3C4LE3EiORltHd9M05pq6FOlVeiophzRbMo50Sbz1ehl8K3Z+jw9+vmgnXefY1hz8X+2wA==" }, "node_modules/nunjucks": { - "version": "3.2.3", - "resolved": "https://registry.npmmirror.com/nunjucks/-/nunjucks-3.2.3.tgz", - "integrity": "sha512-psb6xjLj47+fE76JdZwskvwG4MYsQKXUtMsPh6U0YMvmyjRtKRFcxnlXGWglNybtNTNVmGdp94K62/+NjF5FDQ==", + "version": "3.2.4", + "resolved": "https://registry.npmmirror.com/nunjucks/-/nunjucks-3.2.4.tgz", + "integrity": "sha512-26XRV6BhkgK0VOxfbU5cQI+ICFUtMLixv1noZn1tGU38kQH5A5nmmbk/O45xdyBhD1esk47nKrY0mvQpZIhRjQ==", "dependencies": { "a-sync-waterfall": "^1.0.0", "asap": "^2.0.3", diff --git a/package.json b/package.json index af214101..417600ce 100644 --- a/package.json +++ b/package.json @@ -4,18 +4,15 @@ "description": "", "main": "index.js", "scripts": { - "testrpc": "ganache-cli --mnemonic 'clock radar mass judge dismiss just intact mind resemble fringe diary casino' --gasLimit 13000000 -e 100000", - "test:ci": "scripts/run-test.sh", - "generate-test": "node generate-system.js --mock true && node generate-validatorset.js --mock true && node generate-btclightclient.js --mock true && node generate-candidatehub.js --mock true && node generate-pledgeagent.js --mock true && node generate-slash.js --mock true", "generate-mainnet": "node generate-genesis.js --chainid 1116 --initValidatorSetBytes f90285ea944121f067b0f5135d77c29b2b329e8cb1bd96c96094f8b18cecc98d976ad253d38e4100a73d4e154726ea947f461f8a1c35edecd6816e76eb2e84eb661751ee94f8b18cecc98d976ad253d38e4100a73d4e154726ea94fd806ab93db5742944b7b50ce759e5eee5f6fe5094f8b18cecc98d976ad253d38e4100a73d4e154726ea947ef3a94ad1c443481fb3d86829355ca90477f8b594f8b18cecc98d976ad253d38e4100a73d4e154726ea9467d1ad48f91e131413bd0b04e823f3ae4f81e85394f8b18cecc98d976ad253d38e4100a73d4e154726ea943fb42cab4416024dc1b4c9e21b9acd0dfcef35f694f8b18cecc98d976ad253d38e4100a73d4e154726ea943511e3b8ac7336b99517d324145e9b5bb33e08a494f8b18cecc98d976ad253d38e4100a73d4e154726ea94729f39a54304fcc6ec279684c71491a385d7b9ae94f8b18cecc98d976ad253d38e4100a73d4e154726ea94f44a785fd9f23f0abd443541386e71356ce619dc94f8b18cecc98d976ad253d38e4100a73d4e154726ea942efd3cf0733421aec3e4202480d0a90bd157514994f8b18cecc98d976ad253d38e4100a73d4e154726ea94613b0f519ada008cb99b6130e89122ba416bf15994f8b18cecc98d976ad253d38e4100a73d4e154726ea94c0925eeb800ff6ba4695ded61562a10102152b5f94f8b18cecc98d976ad253d38e4100a73d4e154726ea9419e3c7d7e69f273f3f91c060bb438a007f6fc33c94f8b18cecc98d976ad253d38e4100a73d4e154726ea94e127f110d172a0c4c6209fe045dd71781e8fe9d494f8b18cecc98d976ad253d38e4100a73d4e154726ea94f778dc4a199a440dbe9f16d1e13e185bb179b3b794f8b18cecc98d976ad253d38e4100a73d4e154726 --initMembersBytes f86994548e6acce441866674e04ab84587af2d394034c094bb06d463bc143eecc4a0cfa35e0346d5690fa9f694e2fe60f349c6e1a85caad1d22200c289da40dc1294b198db68258f06e79d415a0998be7f9b38ea722694dd173b85f306128f1b10d7d7219059c28c6d6c09", - "generate-testnet": "node generate-genesis.js --chainid 1115 --initValidatorSetBytes f8d7ea9401bca3615d24d3c638836691517b2b9b49b054b1943ae030dc3717c66f63d6e8f1d1508a5c941ff46dea94a458499604a85e90225a14946f36368ae24df16d94de442f5ba55687a24f04419424e0dc2593cc9f4cea945e00c0d5c4c10d4c805aba878d51129a89d513e094cb089be171e256acdaac1ebbeb32ffba0dd438eeea941cd652bc64af3f09b490daae27f46e53726ce230940a53b7e0ffd97357e444b85f4d683c1d8e22879aea94da37ccecbb2d7c83ae27ee2bebfe8ebce162c60094d82c24274ebbfe438788d684dc6034c3c67664a4 --initMembersBytes f83f9491fb7d8a73d2752830ea189737ea0e007f999b949448bfbc530e7c54c332b0fae07312fba7078b878994de60b7d0e6b758ca5dd8c61d377a2c5f1af51ec1", - "generate-testnet2": "node generate-genesis.js --chainid 1114 --initValidatorSetBytes f8d7ea9401bca3615d24d3c638836691517b2b9b49b054b19401bca3615d24d3c638836691517b2b9b49b054b1ea94a458499604a85e90225a14946f36368ae24df16d94a458499604a85e90225a14946f36368ae24df16dea945e00c0d5c4c10d4c805aba878d51129a89d513e0945e00c0d5c4c10d4c805aba878d51129a89d513e0ea941cd652bc64af3f09b490daae27f46e53726ce230941cd652bc64af3f09b490daae27f46e53726ce230ea94da37ccecbb2d7c83ae27ee2bebfe8ebce162c60094da37ccecbb2d7c83ae27ee2bebfe8ebce162c600 --initMembersBytes f83f9491fb7d8a73d2752830ea189737ea0e007f999b949448bfbc530e7c54c332b0fae07312fba7078b878994de60b7d0e6b758ca5dd8c61d377a2c5f1af51ec1" + "generate-testnet": "node generate-genesis.js --chainid 1115 --initValidatorSetBytes f8d7ea9401bca3615d24d3c638836691517b2b9b49b054b1943ae030dc3717c66f63d6e8f1d1508a5c941ff46dea94a458499604a85e90225a14946f36368ae24df16d94de442f5ba55687a24f04419424e0dc2593cc9f4cea945e00c0d5c4c10d4c805aba878d51129a89d513e094cb089be171e256acdaac1ebbeb32ffba0dd438eeea941cd652bc64af3f09b490daae27f46e53726ce230940a53b7e0ffd97357e444b85f4d683c1d8e22879aea94da37ccecbb2d7c83ae27ee2bebfe8ebce162c60094d82c24274ebbfe438788d684dc6034c3c67664a4 --initMembersBytes f83f9491fb7d8a73d2752830ea189737ea0e007f999b949448bfbc530e7c54c332b0fae07312fba7078b878994de60b7d0e6b758ca5dd8c61d377a2c5f1af51ec1" }, "author": "", "license": "MIT", "dependencies": { "commander": "^3.0.1", - "nunjucks": "^3.2.3", + "es5-ext": "^0.10.64", + "nunjucks": "^3.2.4", "rlp": "^2.2.7", "web3": "^1.9.0" } diff --git a/requirements.txt b/requirements.txt index 5ad08ff4..b4670613 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,2 @@ eth-brownie==1.19.4 PyYAML==5.4.1 -ecdsa==0.17.0 \ No newline at end of file diff --git a/tests/utils.py b/tests/utils.py index 55de9e92..252e3546 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,14 +1,11 @@ import random -import pathlib import codecs import hashlib -import ecdsa -import yaml from web3 import Web3 from brownie.network.transaction import TransactionReceipt from brownie.network.account import LocalAccount -from brownie import accounts, chain, web3, history +from brownie import chain, web3, history from eth_account import Account from eth_abi import encode from hashlib import sha256 @@ -44,56 +41,6 @@ def expect_event_not_emitted(tx_receipt: TransactionReceipt, event_name): assert event_name not in tx_receipt.events -def get_mnemonic() -> str: - current_path = pathlib.Path(__file__) - config_file_path = current_path.parent.parent / "brownie-config.yaml" - with open(config_file_path, "r") as f: - data = yaml.load(f.read(), Loader=yaml.CLoader) - return data['networks']['development']['cmd_settings']['mnemonic'] - - -def get_private_key_by_idx(idx): - account = accounts.from_mnemonic(get_mnemonic(), offset=idx) - return account.private_key - - -def pk2public_key(pk, compressed=False): - if pk.startswith('0x'): - private_key_bytes = Web3.toBytes(hexstr=pk) - else: - private_key_bytes = codecs.decode(pk, 'hex') - - # Generating a public key in bytes using SECP256k1 & ecdsa library - public_key_raw = ecdsa.SigningKey.from_string(private_key_bytes, curve=ecdsa.SECP256k1).verifying_key - public_key_bytes = public_key_raw.to_string() - - # Hex encoding the public key from bytes - public_key_hex = codecs.encode(public_key_bytes, 'hex') - - # Bitcoin uncompressed public key begins with bytes 0x04 so we have to add the bytes at the start - public_key = (b'04' + public_key_hex).decode('utf-8') - if not compressed: - return '0x' + public_key - - # Checking if the last byte is odd or even - if ord(bytearray.fromhex(public_key[-2:])) % 2 == 0: - public_key_compressed = '02' - else: - public_key_compressed = '03' - # Add bytes 0x02 to the X of the key if even or 0x03 if odd - public_key_compressed += public_key[2:66] - return '0x' + public_key_compressed - - -def get_public_key_by_idx(idx: int, compressed=False): - return pk2public_key(get_private_key_by_idx(idx), compressed) - - -def get_public_key_by_address(address, compressed=False): - idx = [account.address for account in accounts].index(address) - return get_public_key_by_idx(idx, compressed) - - def public_key2PKHash(public_key): if public_key.startswith('0x'): public_key_bytes = Web3.toBytes(hexstr=public_key)