prettier on js - reorder setup.py - rm obsolete and dupes. Vers updates (#297)

This commit is contained in:
Gene Hoffman 2020-06-24 14:30:58 -07:00
parent 30a1a53c8e
commit 7bc4e36c18
7 changed files with 288 additions and 277 deletions

View File

@ -1,64 +1,64 @@
const chia = require('../../util/chia');
const chia = require("../../util/chia");
describe('chia', () => {
it('converts number mojo to chia', () => {
const result = chia.mojo_to_chia(1000000);
describe("chia", () => {
it("converts number mojo to chia", () => {
const result = chia.mojo_to_chia(1000000);
expect(result).toBe(0.000001);
});
it('converts string mojo to chia', () => {
const result = chia.mojo_to_chia('1000000');
expect(result).toBe(0.000001);
});
it("converts string mojo to chia", () => {
const result = chia.mojo_to_chia("1000000");
expect(result).toBe(0.000001);
});
it('converts number mojo to chia string', () => {
const result = chia.mojo_to_chia_string(1000000);
expect(result).toBe(0.000001);
});
it("converts number mojo to chia string", () => {
const result = chia.mojo_to_chia_string(1000000);
expect(result).toBe('0.000001');
});
it('converts string mojo to chia string', () => {
const result = chia.mojo_to_chia_string('1000000');
expect(result).toBe("0.000001");
});
it("converts string mojo to chia string", () => {
const result = chia.mojo_to_chia_string("1000000");
expect(result).toBe('0.000001');
});
it('converts number chia to mojo', () => {
const result = chia.chia_to_mojo(0.000001);
expect(result).toBe("0.000001");
});
it("converts number chia to mojo", () => {
const result = chia.chia_to_mojo(0.000001);
expect(result).toBe(1000000);
});
it('converts string chia to mojo', () => {
const result = chia.chia_to_mojo('0.000001');
expect(result).toBe(1000000);
});
it("converts string chia to mojo", () => {
const result = chia.chia_to_mojo("0.000001");
expect(result).toBe(1000000);
});
it('converts number mojo to colouredcoin', () => {
const result = chia.mojo_to_colouredcoin(1000000);
expect(result).toBe(1000000);
});
it("converts number mojo to colouredcoin", () => {
const result = chia.mojo_to_colouredcoin(1000000);
expect(result).toBe(1000);
});
it('converts string mojo to colouredcoin', () => {
const result = chia.mojo_to_colouredcoin('1000000');
expect(result).toBe(1000);
});
it("converts string mojo to colouredcoin", () => {
const result = chia.mojo_to_colouredcoin("1000000");
expect(result).toBe(1000);
});
it('converts number mojo to colouredcoin string', () => {
const result = chia.mojo_to_colouredcoin_string(1000000);
expect(result).toBe(1000);
});
it("converts number mojo to colouredcoin string", () => {
const result = chia.mojo_to_colouredcoin_string(1000000);
expect(result).toBe('1,000');
});
it('converts string mojo to colouredcoin string', () => {
const result = chia.mojo_to_colouredcoin_string('1000000');
expect(result).toBe("1,000");
});
it("converts string mojo to colouredcoin string", () => {
const result = chia.mojo_to_colouredcoin_string("1000000");
expect(result).toBe('1,000');
});
it('converts number colouredcoin to mojo', () => {
const result = chia.colouredcoin_to_mojo(1000);
expect(result).toBe("1,000");
});
it("converts number colouredcoin to mojo", () => {
const result = chia.colouredcoin_to_mojo(1000);
expect(result).toBe(1000000);
});
it('converts string colouredcoin to mojo', () => {
const result = chia.colouredcoin_to_mojo('1000');
expect(result).toBe(1000000);
});
it("converts string colouredcoin to mojo", () => {
const result = chia.colouredcoin_to_mojo("1000");
expect(result).toBe(1000000);
});
expect(result).toBe(1000000);
});
});

View File

@ -1,55 +1,69 @@
const { createHash } = require('crypto');
const header = require('../../util/header');
const { createHash } = require("crypto");
const header = require("../../util/header");
describe('header', () => {
beforeAll(() => {
Object.assign(window, {
crypto: {
subtle: {
digest: (algorithm, buf) =>
createHash('sha256')
.update(buf)
.digest()
}
}
});
describe("header", () => {
beforeAll(() => {
Object.assign(window, {
crypto: {
subtle: {
digest: (algorithm, buf) =>
createHash("sha256")
.update(buf)
.digest()
}
}
});
describe('#hash_header', () => {
it('hashes a header', async() => {
const headerHash = await header.hash_header({
data: {
additions_root:
'0x0000000000000000000000000000000000000000000000000000000000000000',
aggregated_signature: null,
coinbase: {
amount: '14000000000000',
parent_coin_info: '0x0000000000000000000000000000000000000000000000000000000000001268',
puzzle_hash: '0xa927f72c69e0cc51098a41e1e0ea9d6894e961d1db80b4452cdf33e77f20da9e'
},
coinbase_signature: {
sig: '0x4ba15d5506dce0bd8ade17dbb423a3277cc6de83b5667a9ac7511dd6e862eeb847a8918227ac0f774526dcd12d23494209d4c450c023369df0cb03e3d18a1dbd986723d2dd05e70cedb471c98a0b6bdf47ad99ef6168d179a8b68084eae4b892'
},
cost: '0',
extension_data: '0x0000000000000000000000000000000000000000000000000000000000000000',
fees_coin: {
amount: '2000000000000',
parent_coin_info: '0xd34ea9ed5d0f43bfd98dbdea2e3f14d637c965f9f9addb618d163504f7560714',
puzzle_hash: '0xa927f72c69e0cc51098a41e1e0ea9d6894e961d1db80b4452cdf33e77f20da9e'
},
filter_hash: '0x0000000000000000000000000000000000000000000000000000000000000000',
generator_hash: '0x0000000000000000000000000000000000000000000000000000000000000000',
height: 4712,
prev_header_hash: '0xb904cb37532f9b6f68088264c644d957f4aa844333d24bc9c2b30bf7859437d6',
proof_of_space_hash: '0x1a853b8020f8c5b72ef4fb0656213cbfdb30bbc3dfe368527d6d83f50e7acf69',
removals_root: '0x0000000000000000000000000000000000000000000000000000000000000000',
timestamp: '1591371814',
total_iters: '168608294357',
weight:'3520789508784128'
},
harvester_signature: '0x53d04fa0ee31bdc249e6db50161a6dc09d1c48ad011533b10a3eda25eb456a8b3562a1509b97f1931e334d5ed8ec6593133ecbbec5c423b733ea3cdfccc3022a7c09b0fc87fd4d0fd6cbfbedbb69d9fd43aab5c07e3452cb1f91524678340b50'
});
expect(headerHash).toBe('365d165727ba1279aceecf8a4a8188a7a5152e06bf7825584f272014947af7e5');
});
});
describe("#hash_header", () => {
it("hashes a header", async () => {
const headerHash = await header.hash_header({
data: {
additions_root:
"0x0000000000000000000000000000000000000000000000000000000000000000",
aggregated_signature: null,
coinbase: {
amount: "14000000000000",
parent_coin_info:
"0x0000000000000000000000000000000000000000000000000000000000001268",
puzzle_hash:
"0xa927f72c69e0cc51098a41e1e0ea9d6894e961d1db80b4452cdf33e77f20da9e"
},
coinbase_signature: {
sig:
"0x4ba15d5506dce0bd8ade17dbb423a3277cc6de83b5667a9ac7511dd6e862eeb847a8918227ac0f774526dcd12d23494209d4c450c023369df0cb03e3d18a1dbd986723d2dd05e70cedb471c98a0b6bdf47ad99ef6168d179a8b68084eae4b892"
},
cost: "0",
extension_data:
"0x0000000000000000000000000000000000000000000000000000000000000000",
fees_coin: {
amount: "2000000000000",
parent_coin_info:
"0xd34ea9ed5d0f43bfd98dbdea2e3f14d637c965f9f9addb618d163504f7560714",
puzzle_hash:
"0xa927f72c69e0cc51098a41e1e0ea9d6894e961d1db80b4452cdf33e77f20da9e"
},
filter_hash:
"0x0000000000000000000000000000000000000000000000000000000000000000",
generator_hash:
"0x0000000000000000000000000000000000000000000000000000000000000000",
height: 4712,
prev_header_hash:
"0xb904cb37532f9b6f68088264c644d957f4aa844333d24bc9c2b30bf7859437d6",
proof_of_space_hash:
"0x1a853b8020f8c5b72ef4fb0656213cbfdb30bbc3dfe368527d6d83f50e7acf69",
removals_root:
"0x0000000000000000000000000000000000000000000000000000000000000000",
timestamp: "1591371814",
total_iters: "168608294357",
weight: "3520789508784128"
},
harvester_signature:
"0x53d04fa0ee31bdc249e6db50161a6dc09d1c48ad011533b10a3eda25eb456a8b3562a1509b97f1931e334d5ed8ec6593133ecbbec5c423b733ea3cdfccc3022a7c09b0fc87fd4d0fd6cbfbedbb69d9fd43aab5c07e3452cb1f91524678340b50"
});
expect(headerHash).toBe(
"365d165727ba1279aceecf8a4a8188a7a5152e06bf7825584f272014947af7e5"
);
});
});
});

View File

@ -1,127 +1,127 @@
const units = require('../../util/units');
const units = require("../../util/units");
describe('units', () => {
describe('#getUnit', () => {
it('gets unit of chia', () => {
const result = units.getUnit('chia');
describe("units", () => {
describe("#getUnit", () => {
it("gets unit of chia", () => {
const result = units.getUnit("chia");
expect(result).toBe(1);
});
it('gets unit of mojo', () => {
const result = units.getUnit('mojo');
expect(result).toBe(1e-12);
});
it('gets unit of coloured coin', () => {
const result = units.getUnit('colouredcoin');
expect(result).toBe(1e-9);
});
it('supports uppercase characters', () => {
const result = units.getUnit('CHIA');
expect(result).toBe(1);
});
it('gets unit of chia using alias', () => {
const result = units.getUnit('ch');
expect(result).toBe(1);
});
it('gets unit of mojo using alias', () => {
const result = units.getUnit('mj');
expect(result).toBe(1e-12);
});
it('gets unit of coloured coin using alias', () => {
const result = units.getUnit('cc');
expect(result).toBe(1e-9);
});
it('throws an error if unit is not supported', () => {
try {
units.getUnit('bitcoin');
} catch (err) {
expect(err).toEqual(new Error('Unit \'bitcoin\' is not supported'));
}
});
expect(result).toBe(1);
});
describe('#getDisplay', () => {
it('gets display of chia', () => {
const result = units.getDisplay('chia');
it("gets unit of mojo", () => {
const result = units.getUnit("mojo");
expect(result).toEqual({
format: "{amount} CH",
fractionDigits: 12
});
});
it('gets display of mojo', () => {
const result = units.getDisplay('mojo');
expect(result).toEqual({
format: "{amount} MJ",
fractionDigits: 0
});
});
it('gets display of coloured coin', () => {
const result = units.getDisplay('colouredcoin');
expect(result).toEqual({
format: "{amount} CC",
fractionDigits: 3
});
});
it('throws an error if unit is not supported', () => {
try {
units.getDisplay('bitcoin');
} catch (err) {
expect(err).toEqual(new Error('Unit \'bitcoin\' is not supported'));
}
});
expect(result).toBe(1e-12);
});
describe('#setUnit', () => {
it('adds a new unit', () => {
units.setUnit('bitcoin', 1);
it("gets unit of coloured coin", () => {
const result = units.getUnit("colouredcoin");
const result = units.getUnit('bitcoin');
expect(result).toEqual(1);
});
it('modifies an existing unit', () => {
units.setUnit('chia', 9);
const result = units.getUnit('chia');
expect(result).toEqual(9);
units.setUnit('chia', 1);
});
expect(result).toBe(1e-9);
});
describe('#setDisplay', () => {
it('sets a new display', () => {
units.setDisplay('bitcoin', {
format: "{amount} BTC",
fractionDigits: 0
});
it("supports uppercase characters", () => {
const result = units.getUnit("CHIA");
const result = units.getDisplay('bitcoin');
expect(result).toEqual({
format: "{amount} BTC",
fractionDigits: 0
});
});
it('updates an existing display', () => {
units.setDisplay('chia', {
format: "{amount} TXCH",
fractionDigits: 0
});
const result = units.getDisplay('chia');
expect(result).toEqual({
format: "{amount} TXCH",
fractionDigits: 0
});
});
expect(result).toBe(1);
});
it("gets unit of chia using alias", () => {
const result = units.getUnit("ch");
expect(result).toBe(1);
});
it("gets unit of mojo using alias", () => {
const result = units.getUnit("mj");
expect(result).toBe(1e-12);
});
it("gets unit of coloured coin using alias", () => {
const result = units.getUnit("cc");
expect(result).toBe(1e-9);
});
it("throws an error if unit is not supported", () => {
try {
units.getUnit("bitcoin");
} catch (err) {
expect(err).toEqual(new Error("Unit 'bitcoin' is not supported"));
}
});
});
describe("#getDisplay", () => {
it("gets display of chia", () => {
const result = units.getDisplay("chia");
expect(result).toEqual({
format: "{amount} CH",
fractionDigits: 12
});
});
it("gets display of mojo", () => {
const result = units.getDisplay("mojo");
expect(result).toEqual({
format: "{amount} MJ",
fractionDigits: 0
});
});
it("gets display of coloured coin", () => {
const result = units.getDisplay("colouredcoin");
expect(result).toEqual({
format: "{amount} CC",
fractionDigits: 3
});
});
it("throws an error if unit is not supported", () => {
try {
units.getDisplay("bitcoin");
} catch (err) {
expect(err).toEqual(new Error("Unit 'bitcoin' is not supported"));
}
});
});
describe("#setUnit", () => {
it("adds a new unit", () => {
units.setUnit("bitcoin", 1);
const result = units.getUnit("bitcoin");
expect(result).toEqual(1);
});
it("modifies an existing unit", () => {
units.setUnit("chia", 9);
const result = units.getUnit("chia");
expect(result).toEqual(9);
units.setUnit("chia", 1);
});
});
describe("#setDisplay", () => {
it("sets a new display", () => {
units.setDisplay("bitcoin", {
format: "{amount} BTC",
fractionDigits: 0
});
const result = units.getDisplay("bitcoin");
expect(result).toEqual({
format: "{amount} BTC",
fractionDigits: 0
});
});
it("updates an existing display", () => {
units.setDisplay("chia", {
format: "{amount} TXCH",
fractionDigits: 0
});
const result = units.getDisplay("chia");
expect(result).toEqual({
format: "{amount} TXCH",
fractionDigits: 0
});
});
});
});

View File

@ -1,47 +1,47 @@
const utils = require('../../util/utils');
const utils = require("../../util/utils");
describe('utils', () => {
describe('#unix_to_short_date', () => {
it('converts unix timestamp to a short date', () => {
const result = utils.unix_to_short_date(1589578957);
describe("utils", () => {
describe("#unix_to_short_date", () => {
it("converts unix timestamp to a short date", () => {
const result = utils.unix_to_short_date(1589578957);
expect(result).toBe('05/15/2020 22:42:37');
});
expect(result).toBe("05/15/2020 22:42:37");
});
describe('#get_query_variable', () => {
beforeEach(() => {
delete global.location;
global.location = { search: '&x=y&foo=bar&baz=bop' };
});
it('gets query variable from location', () => {
const result = utils.get_query_variable('foo');
expect(result).toBe('bar');
});
it('cannot find a variable', () => {
const result = utils.get_query_variable('chia');
expect(result).toBeUndefined();
});
});
describe("#get_query_variable", () => {
beforeEach(() => {
delete global.location;
global.location = { search: "&x=y&foo=bar&baz=bop" };
});
describe('#hex_to_array', () => {
it('converts lowercase hex string to an array', () => {
const result = utils.hex_to_array('0xeeaa');
it("gets query variable from location", () => {
const result = utils.get_query_variable("foo");
expect(result).toEqual([238, 170]);
});
it('converts uppercase hex string to an array', () => {
const result = utils.hex_to_array('0xEEAA');
expect(result).toEqual([238, 170]);
});
expect(result).toBe("bar");
});
describe('#arr_to_hex', () => {
it('converts an array to a hex string', () => {
const result = utils.arr_to_hex([238, 170]);
expect(result).toBe('eeaa');
});
it("cannot find a variable", () => {
const result = utils.get_query_variable("chia");
expect(result).toBeUndefined();
});
});
describe("#hex_to_array", () => {
it("converts lowercase hex string to an array", () => {
const result = utils.hex_to_array("0xeeaa");
expect(result).toEqual([238, 170]);
});
it("converts uppercase hex string to an array", () => {
const result = utils.hex_to_array("0xEEAA");
expect(result).toEqual([238, 170]);
});
});
describe("#arr_to_hex", () => {
it("converts an array to a hex string", () => {
const result = utils.arr_to_hex([238, 170]);
expect(result).toBe("eeaa");
});
});
});

View File

@ -117,4 +117,4 @@ export const mojo_to_colouredcoin_string = mojo => {
return chia_formatter(Number(mojo), "mojo")
.to("colouredcoin")
.toString();
};
};

View File

@ -2,10 +2,9 @@ Click==7.0
appdirs==1.4.3
autoflake==1.3.1
black==19.10b0
cbor2==5.1.0
cffi==1.13.2
entrypoints==0.3
flake8==3.7.9
flake8==3.8.3
idna==2.8
importlib-metadata==1.4.0
isort==4.3.21
@ -14,7 +13,7 @@ more-itertools==8.1.0
multidict==4.7.4
mypy-extensions==0.4.3
mypy==0.782
packaging==20.0
packaging==20.4
pathspec==0.7.0
pluggy==0.13.1
py==1.8.1
@ -22,14 +21,13 @@ pycodestyle==2.5.0
pycparser==2.19
pyflakes==2.1.1
pyparsing==2.4.6
pytest-asyncio==0.10.0
pytest==5.3.4
pytest-asyncio==0.14.0
pytest==5.4.3
regex==2020.1.8
setuptools-scm==3.4.2
setuptools-scm==4.1.2
six==1.14.0
toml==0.10.0
typed-ast==1.4.1
typing-extensions==3.7.4.1
wcwidth==0.1.8
websockets==8.1.0
zipp==2.0.0

View File

@ -4,24 +4,23 @@ from setuptools import setup
dependencies = [
"aiter==0.13.20191203", # Used for async generator tools
"blspy==0.1.28", # Signature library
"cbor2==5.1.0", # Used for network wire format
"clvm==0.4", # contract language
"PyYAML==5.3.1", # Used for config file format
"aiosqlite==0.13.0", # asyncio wrapper for sqlite, to store blocks
"aiohttp==3.6.2", # HTTP server for full node rpc
"colorlog==4.1.0", # Adds color to logs
"chiavdf==0.12.18", # timelord and vdf verification
"chiabip158==0.14", # bip158-style wallet filters
"chiapos==0.12.22", # proof of space
"sortedcontainers==2.1.0", # For maintaining sorted mempools
"websockets==8.1.0", # For use in wallet RPC and electron UI
"clvm==0.4", # contract language
"clvm-tools==0.1.1", # clvm compiler tools
"bitstring==3.1.6",
"keyring==21.2.1",
"keyring_jeepney==0.2",
"keyrings.cryptfile==1.3.4",
"aiosqlite==0.13.0", # asyncio wrapper for sqlite, to store blocks
"aiohttp==3.6.2", # HTTP server for full node rpc
"bitstring==3.1.7", # Binary data management library
"cbor2==5.1.0", # Used for network wire format
"colorlog==4.1.0", # Adds color to logs
"concurrent-log-handler==0.9.16", # Concurrently log and rotate logs
"cryptography==2.9.2", #Python cryptography library for TLS
"concurrent-log-handler==0.9.16", # Log to a file concurrently and rotate logs
"keyring==21.2.1", # Store keys in MacOS Keychain, Windows Credential Locker
"keyrings.cryptfile==1.3.4", # Secure storage for keys on Linux (Will be replaced)
"PyYAML==5.3.1", # Used for config file format
"sortedcontainers==2.2.2", # For maintaining sorted mempools
"websockets==8.1.0", # For use in wallet RPC and electron UI
]
upnp_dependencies = [