Session Kit 1.1.0 + fixing tests

This commit is contained in:
Aaron Cox
2023-11-10 09:48:25 -08:00
parent 507c61627f
commit f8dd6352ba
15 changed files with 399 additions and 90 deletions
+3 -3
View File
@@ -6,13 +6,13 @@ lib: ${SRC_FILES} package.json tsconfig.json node_modules rollup.config.js
.PHONY: test
test: node_modules
@TS_NODE_PROJECT='./test/tsconfig.json' ${BIN}/mocha \
@TS_NODE_PROJECT='./test/tsconfig.json' MOCK_DIR=./test/data ${BIN}/mocha \
-u tdd -r ts-node/register --extension ts test/*.ts --grep '$(grep)'
.PHONY: coverage
coverage: node_modules
@TS_NODE_PROJECT='./test/tsconfig.json' ${BIN}/nyc --reporter=html \
${BIN}/mocha -u tdd -r ts-node/register --extension ts test/*.ts \
${BIN}/mocha MOCK_DIR=./test/data -u tdd -r ts-node/register --extension ts test/*.ts \
-R nyan && open coverage/index.html
.PHONY: lint
@@ -21,7 +21,7 @@ lint: node_modules
.PHONY: ci-test
ci-test: node_modules
@TS_NODE_PROJECT='./test/tsconfig.json' ${BIN}/nyc --reporter=text \
@TS_NODE_PROJECT='./test/tsconfig.json' MOCK_DIR=./test/data ${BIN}/nyc --reporter=text \
${BIN}/mocha -u tdd -r ts-node/register --extension ts test/*.ts -R list
.PHONY: ci-lint
+2 -1
View File
@@ -20,7 +20,7 @@
"prepare": "make"
},
"dependencies": {
"@wharfkit/antelope": "^0.7.3",
"@wharfkit/antelope": "^1.0.0",
"bn.js": "^4.11.9",
"tslib": "^2.1.0"
},
@@ -30,6 +30,7 @@
"@types/node": "^14.14.28",
"@typescript-eslint/eslint-plugin": "^4.15.1",
"@typescript-eslint/parser": "^4.15.1",
"@wharfkit/mock-data": "^1.2.0",
"assert": "^2.0.0",
"eslint": "^7.19.0",
"eslint-config-prettier": "^7.0.0",
@@ -0,0 +1,32 @@
{
"request": {
"path": "https://eos.greymass.com/v1/chain/get_info",
"params": {
"method": "GET"
}
},
"status": 200,
"json": {
"server_version": "43873e82",
"chain_id": "aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906",
"head_block_num": 340895511,
"last_irreversible_block_num": 340895176,
"last_irreversible_block_id": "1451a5c88df252644e99a33ca328c3bd8d5e81361b9524b10a14b6901f6a2f55",
"head_block_id": "1451a717d660644b1e45760e39f9cfab50a983bb926940325b6f543987ca7366",
"head_block_time": "2023-11-10T17:36:11.000",
"head_block_producer": "bitfinexeos1",
"virtual_block_cpu_limit": 200000,
"virtual_block_net_limit": 1048576000,
"block_cpu_limit": 200000,
"block_net_limit": 1048576,
"server_version_string": "v3.2.3-hotfix",
"fork_db_head_block_num": 340895511,
"fork_db_head_block_id": "1451a717d660644b1e45760e39f9cfab50a983bb926940325b6f543987ca7366",
"server_full_version_string": "v3.2.3-hotfix-43873e822160be5e5f364fd867e3c7d27162cd0c-dirty",
"total_cpu_weight": "383322901692810",
"total_net_weight": "96096575077807",
"earliest_available_block_num": 340722102,
"last_irreversible_block_time": "2023-11-10T17:33:23.500"
},
"text": "{\"server_version\":\"43873e82\",\"chain_id\":\"aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906\",\"head_block_num\":340895511,\"last_irreversible_block_num\":340895176,\"last_irreversible_block_id\":\"1451a5c88df252644e99a33ca328c3bd8d5e81361b9524b10a14b6901f6a2f55\",\"head_block_id\":\"1451a717d660644b1e45760e39f9cfab50a983bb926940325b6f543987ca7366\",\"head_block_time\":\"2023-11-10T17:36:11.000\",\"head_block_producer\":\"bitfinexeos1\",\"virtual_block_cpu_limit\":200000,\"virtual_block_net_limit\":1048576000,\"block_cpu_limit\":200000,\"block_net_limit\":1048576,\"server_version_string\":\"v3.2.3-hotfix\",\"fork_db_head_block_num\":340895511,\"fork_db_head_block_id\":\"1451a717d660644b1e45760e39f9cfab50a983bb926940325b6f543987ca7366\",\"server_full_version_string\":\"v3.2.3-hotfix-43873e822160be5e5f364fd867e3c7d27162cd0c-dirty\",\"total_cpu_weight\":\"383322901692810\",\"total_net_weight\":\"96096575077807\",\"earliest_available_block_num\":340722102,\"last_irreversible_block_time\":\"2023-11-10T17:33:23.500\"}"
}
@@ -4,9 +4,9 @@
"access-control-allow-methods": "GET, POST, OPTIONS",
"access-control-allow-origin": "*",
"connection": "close",
"content-length": "188",
"content-length": "168",
"content-type": "application/json",
"date": "Sat, 25 Sep 2021 08:01:06 GMT",
"date": "Mon, 04 Sep 2023 19:09:10 GMT",
"host": "eos.greymass.com",
"server": "nginx",
"x-cached": "MISS"
@@ -14,11 +14,10 @@
"status": 200,
"json": {
"rows": [
"00407a10f35a00000452414d434f5245e0be34962c0000000052414d00000000000000000000e03f88f91e5d0d00000004454f5300000000000000000000e03f"
"00407a10f35a00000452414d434f52453e4e92cf4d0000000052414d00000000000000000000e03f97babe970c00000004454f5300000000000000000000e03f"
],
"more": false,
"next_key": "",
"next_key_bytes": ""
"next_key": ""
},
"text": "{\"rows\":[\"00407a10f35a00000452414d434f5245e0be34962c0000000052414d00000000000000000000e03f88f91e5d0d00000004454f5300000000000000000000e03f\"],\"more\":false,\"next_key\":\"\",\"next_key_bytes\":\"\"}"
"text": "{\"rows\":[\"00407a10f35a00000452414d434f52453e4e92cf4d0000000052414d00000000000000000000e03f97babe970c00000004454f5300000000000000000000e03f\"],\"more\":false,\"next_key\":\"\"}"
}
@@ -0,0 +1,130 @@
{
"request": {
"path": "https://eos.greymass.com/v1/chain/get_account",
"params": {
"method": "POST",
"body": "{\"account_name\":\"b1\"}"
}
},
"status": 200,
"json": {
"account_name": "b1",
"head_block_num": 340895515,
"head_block_time": "2023-11-10T17:36:13.000",
"privileged": false,
"last_code_update": "1970-01-01T00:00:00.000",
"created": "2018-06-09T11:58:03.500",
"core_liquid_balance": "0.2966 EOS",
"ram_quota": 9487,
"net_weight": "350078512340",
"cpu_weight": "296624975145",
"net_limit": {
"used": 271,
"available": "660087025601",
"max": "660087025872",
"last_usage_update_time": "2022-08-23T01:41:35.000",
"current_used": 0
},
"cpu_limit": {
"used": 4647,
"available": 26738756,
"max": 26743403,
"last_usage_update_time": "2022-08-23T01:41:35.000",
"current_used": 0
},
"ram_usage": 5010,
"permissions": [
{
"perm_name": "active",
"parent": "owner",
"required_auth": {
"threshold": 2,
"keys": [
{
"key": "EOS5BUDFbb2erXiRP8qHQAgVboCHgHGesbCubUfgXYJhnYZKSqNbD",
"weight": 1
},
{
"key": "EOS6hQ6v8vut1V2giQCYha7J225GCzFJtF3o7fy8JYuN7k6fG4n23",
"weight": 1
},
{
"key": "EOS7RodmQofvAxgYBJzfNuwRKr6TWh5LbCBfB4uQ8tjrjQ8Ukkwqq",
"weight": 1
},
{
"key": "EOS7c9jHNgbtTMYgpXvmTb1kW61oH6kwfGioWk75ugDMhsywe6rWu",
"weight": 1
}
],
"accounts": [],
"waits": []
},
"linked_actions": []
},
{
"perm_name": "owner",
"parent": "",
"required_auth": {
"threshold": 2,
"keys": [
{
"key": "EOS5BUDFbb2erXiRP8qHQAgVboCHgHGesbCubUfgXYJhnYZKSqNbD",
"weight": 1
},
{
"key": "EOS6hQ6v8vut1V2giQCYha7J225GCzFJtF3o7fy8JYuN7k6fG4n23",
"weight": 1
},
{
"key": "EOS7RodmQofvAxgYBJzfNuwRKr6TWh5LbCBfB4uQ8tjrjQ8Ukkwqq",
"weight": 1
},
{
"key": "EOS7c9jHNgbtTMYgpXvmTb1kW61oH6kwfGioWk75ugDMhsywe6rWu",
"weight": 1
}
],
"accounts": [],
"waits": []
},
"linked_actions": []
}
],
"total_resources": {
"owner": "b1",
"net_weight": "35007851.2340 EOS",
"cpu_weight": "29662497.5145 EOS",
"ram_bytes": 8087
},
"self_delegated_bandwidth": {
"from": "b1",
"to": "b1",
"net_weight": "35007851.2340 EOS",
"cpu_weight": "29662497.5145 EOS"
},
"refund_request": null,
"voter_info": {
"owner": "b1",
"proxy": "",
"producers": [],
"staked": "646723487485",
"last_vote_weight": "2768257912613634048.00000000000000000",
"proxied_vote_weight": "0.00000000000000000",
"is_proxy": 0,
"flags1": 0,
"reserved2": 0,
"reserved3": "0.0000 EOS"
},
"rex_info": null,
"subjective_cpu_bill_limit": {
"used": 0,
"available": 0,
"max": 0,
"last_usage_update_time": "2000-01-01T00:00:00.000",
"current_used": 0
},
"eosio_any_linked_actions": []
},
"text": "{\"account_name\":\"b1\",\"head_block_num\":340895515,\"head_block_time\":\"2023-11-10T17:36:13.000\",\"privileged\":false,\"last_code_update\":\"1970-01-01T00:00:00.000\",\"created\":\"2018-06-09T11:58:03.500\",\"core_liquid_balance\":\"0.2966 EOS\",\"ram_quota\":9487,\"net_weight\":\"350078512340\",\"cpu_weight\":\"296624975145\",\"net_limit\":{\"used\":271,\"available\":\"660087025601\",\"max\":\"660087025872\",\"last_usage_update_time\":\"2022-08-23T01:41:35.000\",\"current_used\":0},\"cpu_limit\":{\"used\":4647,\"available\":26738756,\"max\":26743403,\"last_usage_update_time\":\"2022-08-23T01:41:35.000\",\"current_used\":0},\"ram_usage\":5010,\"permissions\":[{\"perm_name\":\"active\",\"parent\":\"owner\",\"required_auth\":{\"threshold\":2,\"keys\":[{\"key\":\"EOS5BUDFbb2erXiRP8qHQAgVboCHgHGesbCubUfgXYJhnYZKSqNbD\",\"weight\":1},{\"key\":\"EOS6hQ6v8vut1V2giQCYha7J225GCzFJtF3o7fy8JYuN7k6fG4n23\",\"weight\":1},{\"key\":\"EOS7RodmQofvAxgYBJzfNuwRKr6TWh5LbCBfB4uQ8tjrjQ8Ukkwqq\",\"weight\":1},{\"key\":\"EOS7c9jHNgbtTMYgpXvmTb1kW61oH6kwfGioWk75ugDMhsywe6rWu\",\"weight\":1}],\"accounts\":[],\"waits\":[]},\"linked_actions\":[]},{\"perm_name\":\"owner\",\"parent\":\"\",\"required_auth\":{\"threshold\":2,\"keys\":[{\"key\":\"EOS5BUDFbb2erXiRP8qHQAgVboCHgHGesbCubUfgXYJhnYZKSqNbD\",\"weight\":1},{\"key\":\"EOS6hQ6v8vut1V2giQCYha7J225GCzFJtF3o7fy8JYuN7k6fG4n23\",\"weight\":1},{\"key\":\"EOS7RodmQofvAxgYBJzfNuwRKr6TWh5LbCBfB4uQ8tjrjQ8Ukkwqq\",\"weight\":1},{\"key\":\"EOS7c9jHNgbtTMYgpXvmTb1kW61oH6kwfGioWk75ugDMhsywe6rWu\",\"weight\":1}],\"accounts\":[],\"waits\":[]},\"linked_actions\":[]}],\"total_resources\":{\"owner\":\"b1\",\"net_weight\":\"35007851.2340 EOS\",\"cpu_weight\":\"29662497.5145 EOS\",\"ram_bytes\":8087},\"self_delegated_bandwidth\":{\"from\":\"b1\",\"to\":\"b1\",\"net_weight\":\"35007851.2340 EOS\",\"cpu_weight\":\"29662497.5145 EOS\"},\"refund_request\":null,\"voter_info\":{\"owner\":\"b1\",\"proxy\":\"\",\"producers\":[],\"staked\":\"646723487485\",\"last_vote_weight\":\"2768257912613634048.00000000000000000\",\"proxied_vote_weight\":\"0.00000000000000000\",\"is_proxy\":0,\"flags1\":0,\"reserved2\":0,\"reserved3\":\"0.0000 EOS\"},\"rex_info\":null,\"subjective_cpu_bill_limit\":{\"used\":0,\"available\":0,\"max\":0,\"last_usage_update_time\":\"2000-01-01T00:00:00.000\",\"current_used\":0},\"eosio_any_linked_actions\":[]}"
}
@@ -0,0 +1,18 @@
{
"request": {
"path": "https://eos.greymass.com/v1/chain/get_table_rows",
"params": {
"method": "POST",
"body": "{\"code\":\"eosio\",\"scope\":\"\",\"table\":\"powup.state\",\"key_type\":\"name\",\"json\":false}"
}
},
"status": 200,
"json": {
"rows": [
"00002ae97f9fd056000000a0724e180900004e79bb7de00000000080c6a47e8d030000a0724e1809000093c83560e8b96e6000000000000000408051010040787d010000000004454f53000000008017b42c0000000004454f5300000000076ba22b5b0000009ece299b75000000e7694e6500a8a4ff7d425b010000a0724e1809000038e5edf6810300000080c6a47e8d030000a0724e1809000093c83560e8b96e6000000000000000408051010040787d010000000004454f53000000008017b42c0000000004454f530000000091b4bf6d671b00000724ec6d6c1b0000e7694e6501000000010000000000000004454f5300000000"
],
"more": false,
"next_key": ""
},
"text": "{\"rows\":[\"00002ae97f9fd056000000a0724e180900004e79bb7de00000000080c6a47e8d030000a0724e1809000093c83560e8b96e6000000000000000408051010040787d010000000004454f53000000008017b42c0000000004454f5300000000076ba22b5b0000009ece299b75000000e7694e6500a8a4ff7d425b010000a0724e1809000038e5edf6810300000080c6a47e8d030000a0724e1809000093c83560e8b96e6000000000000000408051010040787d010000000004454f53000000008017b42c0000000004454f530000000091b4bf6d671b00000724ec6d6c1b0000e7694e6501000000010000000000000004454f5300000000\"],\"more\":false,\"next_key\":\"\"}"
}
@@ -0,0 +1,18 @@
{
"request": {
"path": "https://eos.greymass.com/v1/chain/get_table_rows",
"params": {
"method": "POST",
"body": "{\"code\":\"eosio\",\"scope\":\"eosio\",\"table\":\"rexpool\",\"key_type\":\"name\",\"json\":false}"
}
},
"status": 200,
"json": {
"rows": [
"003c6ed8140700000004454f5300000000c6cb1eb08700000004454f5300000000fef112020000000004454f5300000000023af7c48e00000004454f5300000000aeec1953f67015000452455800000000000000000000000004454f5300000000f2ad070000000000"
],
"more": false,
"next_key": ""
},
"text": "{\"rows\":[\"003c6ed8140700000004454f5300000000c6cb1eb08700000004454f5300000000fef112020000000004454f5300000000023af7c48e00000004454f5300000000aeec1953f67015000452455800000000000000000000000004454f5300000000f2ad070000000000\"],\"more\":false,\"next_key\":\"\"}"
}
@@ -0,0 +1,18 @@
{
"request": {
"path": "https://eos.greymass.com/v1/chain/get_table_rows",
"params": {
"method": "POST",
"body": "{\"code\":\"eosio\",\"scope\":\"eosio\",\"table\":\"rammarket\",\"key_type\":\"name\",\"json\":false}"
}
},
"status": 200,
"json": {
"rows": [
"00407a10f35a00000452414d434f5245ffcd4f55500000000052414d00000000000000000000e03ffce056a10c00000004454f5300000000000000000000e03f"
],
"more": false,
"next_key": ""
},
"text": "{\"rows\":[\"00407a10f35a00000452414d434f5245ffcd4f55500000000052414d00000000000000000000e03ffce056a10c00000004454f5300000000000000000000e03f\"],\"more\":false,\"next_key\":\"\"}"
}
@@ -0,0 +1,18 @@
{
"request": {
"path": "https://jungle4.greymass.com/v1/chain/get_table_rows",
"params": {
"method": "POST",
"body": "{\"code\":\"eosio\",\"scope\":\"\",\"table\":\"powup.state\",\"key_type\":\"name\",\"json\":false}"
}
},
"status": 200,
"json": {
"rows": [
"00000030d53b0a5a000000a0724e180900000010a5d4e800000000a0724e1809000000a0724e18090000dd751562dd751562000000000000004080510100809698000000000004454f5300000000002f68590000000004454f53000000002cf6c08e4c0000002cf3aa404a00000085ee4d65000030d53b0a5a000000a0724e180900000010a5d4e800000000a0724e1809000000a0724e18090000dd751562dd75156200000000000000408051010040787d010000000004454f53000000008017b42c0000000004454f53000000006e4a6642fd0100006e4750f4fa01000085ee4d6501000000e80300000000000004454f5300000000"
],
"more": false,
"next_key": ""
},
"text": "{\"rows\":[\"00000030d53b0a5a000000a0724e180900000010a5d4e800000000a0724e1809000000a0724e18090000dd751562dd751562000000000000004080510100809698000000000004454f5300000000002f68590000000004454f53000000002cf6c08e4c0000002cf3aa404a00000085ee4d65000030d53b0a5a000000a0724e180900000010a5d4e800000000a0724e1809000000a0724e18090000dd751562dd75156200000000000000408051010040787d010000000004454f53000000008017b42c0000000004454f53000000006e4a6642fd0100006e4750f4fa01000085ee4d6501000000e80300000000000004454f5300000000\"],\"more\":false,\"next_key\":\"\"}"
}
@@ -0,0 +1,32 @@
{
"request": {
"path": "https://jungle4.greymass.com/v1/chain/get_info",
"params": {
"method": "GET"
}
},
"status": 200,
"json": {
"server_version": "905c5cc9",
"chain_id": "73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d",
"head_block_num": 107761721,
"last_irreversible_block_num": 107761390,
"last_irreversible_block_id": "066c4eee01dd56004d35613ee759811dad7a7db92b3e691fd822f9bef3b78850",
"head_block_id": "066c503946353b4af42adf1c0705d8aea8b62a41dc85cb7e43510289c0f2060e",
"head_block_time": "2023-11-10T17:42:27.000",
"head_block_producer": "eosamsterdam",
"virtual_block_cpu_limit": 184188825,
"virtual_block_net_limit": 1048576000,
"block_cpu_limit": 200000,
"block_net_limit": 1048576,
"server_version_string": "v3.1.3",
"fork_db_head_block_num": 107761721,
"fork_db_head_block_id": "066c503946353b4af42adf1c0705d8aea8b62a41dc85cb7e43510289c0f2060e",
"server_full_version_string": "v3.1.3-905c5cc900b4e88aed4ab6912009127bf9f4f140",
"total_cpu_weight": "120613298869319",
"total_net_weight": "117529300091371",
"earliest_available_block_num": 107585477,
"last_irreversible_block_time": "2023-11-10T17:39:41.500"
},
"text": "{\"server_version\":\"905c5cc9\",\"chain_id\":\"73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d\",\"head_block_num\":107761721,\"last_irreversible_block_num\":107761390,\"last_irreversible_block_id\":\"066c4eee01dd56004d35613ee759811dad7a7db92b3e691fd822f9bef3b78850\",\"head_block_id\":\"066c503946353b4af42adf1c0705d8aea8b62a41dc85cb7e43510289c0f2060e\",\"head_block_time\":\"2023-11-10T17:42:27.000\",\"head_block_producer\":\"eosamsterdam\",\"virtual_block_cpu_limit\":184188825,\"virtual_block_net_limit\":1048576000,\"block_cpu_limit\":200000,\"block_net_limit\":1048576,\"server_version_string\":\"v3.1.3\",\"fork_db_head_block_num\":107761721,\"fork_db_head_block_id\":\"066c503946353b4af42adf1c0705d8aea8b62a41dc85cb7e43510289c0f2060e\",\"server_full_version_string\":\"v3.1.3-905c5cc900b4e88aed4ab6912009127bf9f4f140\",\"total_cpu_weight\":\"120613298869319\",\"total_net_weight\":\"117529300091371\",\"earliest_available_block_num\":107585477,\"last_irreversible_block_time\":\"2023-11-10T17:39:41.500\"}"
}
+1 -1
View File
@@ -2,7 +2,7 @@ import 'mocha'
import {strict as assert} from 'assert'
import fetch from 'node-fetch'
import {Asset, APIClient} from '@wharfkit/antelope'
import {APIClient} from '@wharfkit/antelope'
import {PowerUpState, Resources} from '../src'
+33 -39
View File
@@ -1,23 +1,17 @@
import 'mocha'
import {strict as assert} from 'assert'
import {join as joinPath} from 'path'
import fetch from 'node-fetch'
import {APIClient, Asset} from '@wharfkit/antelope'
import {MockProvider} from './utils/mock-provider'
import {Asset} from '@wharfkit/antelope'
import {makeClient} from '@wharfkit/mock-data'
import {PowerUpState, Resources} from '../src'
const resources_eos = new Resources({
api: new APIClient({
provider: new MockProvider(joinPath(__dirname, 'data'), 'https://eos.greymass.com'),
}),
api: makeClient('https://eos.greymass.com'),
})
const resources_jungle = new Resources({
api: new APIClient({
provider: new MockProvider(joinPath(__dirname, 'data'), 'https://jungle3.greymass.com'),
}),
api: makeClient('https://jungle4.greymass.com'),
})
// Fixture for tests to provide reproducable values
@@ -45,12 +39,12 @@ suite('[eos] powerup - cpu calculations', function () {
test('powerup.cpu.us_to_weight', async function () {
const powerup = await resources_eos.v1.powerup.get_state()
const sample = await resources_eos.getSampledUsage()
assert.equal(powerup.cpu.us_to_weight(sample.cpu, 35868), 407590909)
assert.equal(powerup.cpu.us_to_weight(sample.cpu, 35868), 403011235)
})
test('powerup.cpu.weight_to_us', async function () {
const powerup = await resources_eos.v1.powerup.get_state()
const sample = await resources_eos.getSampledUsage()
assert.equal(powerup.cpu.weight_to_us(sample.cpu, 12930064), 1138)
assert.equal(powerup.cpu.weight_to_us(sample.cpu, 12930064), 1151)
})
test('powerup.cpu.allocated', async function () {
const powerup = await resources_eos.v1.powerup.get_state()
@@ -61,14 +55,14 @@ suite('[eos] powerup - cpu calculations', function () {
test('powerup.cpu.reserved', async function () {
const powerup = await resources_eos.v1.powerup.get_state()
assert.equal(powerup.cpu.reserved, 0.03816527191292494)
// 3.816527191292494% represented as float
assert.equal(powerup.cpu.reserved, 0.07891504719871277)
// 7.891504719871277% represented as float
})
test('powerup.cpu.price_per_us(60)', async function () {
const powerup = await resources_eos.v1.powerup.get_state()
const sample = await resources_eos.getSampledUsage()
const price = powerup.cpu.price_per_ms(sample, 60, this.testFixture)
assert.equal(price, 0.0098)
assert.equal(price, 0.0146)
})
test('powerup.cpu.price_per_us(1)', async function () {
const powerup = await resources_eos.v1.powerup.get_state()
@@ -85,41 +79,41 @@ suite('[eos] powerup - cpu calculations', function () {
const price_ms = powerup.cpu.price_per_ms(sample, 1, this.testFixture)
assert.equal(price_us, price_ms)
assert.equal(price_us, 0.0002)
assert.equal(price_us, 0.0003)
})
test('powerup.cpu.price_per_ms(1)', async function () {
const powerup = await resources_eos.v1.powerup.get_state()
const sample = await resources_eos.getSampledUsage()
const price = powerup.cpu.price_per_ms(sample, 1, this.testFixture)
assert.equal(price, 0.0002)
assert.equal(price, 0.0003)
const asset = Asset.from(price, '4,EOS')
assert.equal(String(asset), '0.0002 EOS')
assert.equal(asset.value, 0.0002)
assert.equal(Number(asset.units), 2)
assert.equal(String(asset), '0.0003 EOS')
assert.equal(asset.value, 0.0003)
assert.equal(Number(asset.units), 3)
})
test('powerup.cpu.price_per_ms(1000)', async function () {
const powerup = await resources_eos.v1.powerup.get_state()
const sample = await resources_eos.getSampledUsage()
const price = powerup.cpu.price_per_ms(sample, 1000, this.testFixture)
assert.equal(price, 0.1632)
assert.equal(price, 0.2421)
const asset = Asset.from(price, '4,EOS')
assert.equal(String(asset), '0.1632 EOS')
assert.equal(asset.value, 0.1632)
assert.equal(Number(asset.units), 1632)
assert.equal(String(asset), '0.2421 EOS')
assert.equal(asset.value, 0.2421)
assert.equal(Number(asset.units), 2421)
})
test('powerup.cpu.frac()', async function () {
const powerup = await resources_eos.v1.powerup.get_state()
const sample = await resources_eos.getSampledUsage()
const frac1 = powerup.cpu.frac(sample, 100)
assert.equal(frac1, 2976204)
assert.equal(frac1, 2942764)
const frac1000 = powerup.cpu.frac(sample, 1000000)
assert.equal(frac1000, 29762065741)
assert.equal(frac1000, 29427660509)
})
})
@@ -141,8 +135,8 @@ suite('[eos] powerup - net calculations', function () {
test('powerup.net.reserved', async function () {
const powerup = await resources_eos.v1.powerup.get_state()
assert.equal(powerup.net.reserved, 0.0005123029024892572)
// 0.05123029024892572% represented as float
assert.equal(powerup.net.reserved, 0.004102226924904269)
// 0.4102226924904269% represented as float
})
test('powerup.net.price_per_kb(1000000000000)', async function () {
const powerup = await resources_eos.v1.powerup.get_state()
@@ -161,7 +155,7 @@ suite('[eos] powerup - net calculations', function () {
const sample = await resources_eos.getSampledUsage()
const frac1000 = powerup.net.frac(sample, 1000000)
assert.equal(frac1000, 5586469)
assert.equal(frac1000, 5556098)
})
})
@@ -183,7 +177,7 @@ suite('[jungle] powerup - cpu calculations', function () {
test('powerup.cpu.reserved', async function () {
const powerup = await resources_jungle.v1.powerup.get_state()
assert.equal(powerup.cpu.reserved, 0.00032428358627099564)
assert.equal(powerup.cpu.reserved, 0.022093458117636362)
// 0.032428358627099564% represented as float
})
test('powerup.cpu.price_per_us(1000000)', async function () {
@@ -193,30 +187,30 @@ suite('[jungle] powerup - cpu calculations', function () {
const price_us = powerup.cpu.price_per_us(sample, 1000000, this.testFixture)
const price_ms = powerup.cpu.price_per_ms(sample, 1000, this.testFixture)
assert.equal(price_us, price_ms)
assert.equal(price_ms, 0.008)
assert.equal(price_ms, 0.466)
})
test('powerup.cpu.price_per_ms(1000)', async function () {
const powerup = await resources_jungle.v1.powerup.get_state()
const sample = await resources_eos.getSampledUsage()
const price = powerup.cpu.price_per_ms(sample, 1000, this.testFixture)
assert.equal(price, 0.008)
assert.equal(price, 0.466)
const asset = Asset.from(price, '4,EOS')
assert.equal(String(asset), '0.0080 EOS')
assert.equal(asset.value, 0.008)
assert.equal(Number(asset.units), 80)
assert.equal(String(asset), '0.4660 EOS')
assert.equal(asset.value, 0.466)
assert.equal(Number(asset.units), 4660)
})
test('powerup.cpu.price_per_ms(1000000)', async function () {
const powerup = await resources_jungle.v1.powerup.get_state()
const sample = await resources_eos.getSampledUsage()
const price = powerup.cpu.price_per_ms(sample, 1000000, this.testFixture)
assert.equal(price, 8.1469)
assert.equal(price, 932.4653)
const asset = Asset.from(price, '4,EOS')
assert.equal(String(asset), '8.1469 EOS')
assert.equal(asset.value, 8.1469)
assert.equal(Number(asset.units), 81469)
assert.equal(String(asset), '932.4653 EOS')
assert.equal(asset.value, 932.4653)
assert.equal(Number(asset.units), 9324653)
})
})
+7 -14
View File
@@ -1,17 +1,10 @@
import 'mocha'
import {strict as assert} from 'assert'
import {join as joinPath} from 'path'
import {APIClient} from '@wharfkit/antelope'
import {MockProvider} from './utils/mock-provider'
import {RAMState, Resources} from '../src'
import {makeClient} from '@wharfkit/mock-data'
const eos = new APIClient({
provider: new MockProvider(joinPath(__dirname, 'data'), 'https://eos.greymass.com'),
})
const resources = new Resources({api: eos})
const resources = new Resources({api: makeClient('https://eos.greymass.com')})
suite('[eos] ram calculations', function () {
this.slow(200)
@@ -21,18 +14,18 @@ suite('[eos] ram calculations', function () {
})
test('ram.price_per(100)', async function () {
const ram = await resources.v1.ram.get_state()
assert.equal(ram.price_per(100), 0.0029972483286048305)
assert.equal(ram.price_per(100).value, 0.0016)
})
test('ram.price_per(100000)', async function () {
const ram = await resources.v1.ram.get_state()
assert.equal(ram.price_per(100000), 2.997249892194665)
assert.equal(ram.price_per(100000).value, 1.5723)
})
test('ram.price_per_kb(1)', async function () {
const ram = await resources.v1.ram.get_state()
const control = ram.price_per(1000)
const actual = ram.price_per_kb(1)
assert.equal(control, 0.029972483426912184)
assert.equal(actual, 0.029972483426912184)
assert.equal(actual, control)
assert.equal(control.value, 0.0158)
assert.equal(actual.value, 0.0158)
assert.equal(actual.equals(control), true)
})
})
+17 -22
View File
@@ -1,17 +1,12 @@
import 'mocha'
import {strict as assert} from 'assert'
import {join as joinPath} from 'path'
import {APIClient, Asset} from '@wharfkit/antelope'
import {MockProvider} from './utils/mock-provider'
import {Asset} from '@wharfkit/antelope'
import {Resources, REXState} from '../src'
import {makeClient} from '@wharfkit/mock-data'
const eos = new APIClient({
provider: new MockProvider(joinPath(__dirname, 'data'), 'https://eos.greymass.com'),
})
const resources = new Resources({api: eos})
const resources = new Resources({api: makeClient('https://eos.greymass.com')})
suite('[eos] rex calculations', function () {
this.slow(200)
@@ -21,19 +16,19 @@ suite('[eos] rex calculations', function () {
})
test('rex.reserved', async function () {
const rex = await resources.v1.rex.get_state()
assert.equal(rex.reserved, 0.14616051141573932)
// 14.616051141573932% represented as float
assert.equal(rex.reserved, 0.04960045779382111)
// 04.960045779382111% represented as float
})
test('rex.value', async function () {
const rex = await resources.v1.rex.get_state()
assert.equal(rex.value, 0.00010111009786123536)
// 0.00010111009786123536 EOS/REX
assert.equal(rex.value, 0.00010160262316038182)
// 0.00010160262316038182 EOS/REX
})
test('rex.exchange', async function () {
const rex = await resources.v1.rex.get_state()
const amount = Asset.from('493874015.6505 REX')
const tokens = rex.exchange(amount)
assert.equal(tokens.value, 49935.6501)
assert.equal(tokens.value, 50178.8955)
})
test('rex.price_per(1000)', async function () {
const rex = await resources.v1.rex.get_state()
@@ -41,9 +36,9 @@ suite('[eos] rex calculations', function () {
const price = rex.price_per(usage, 1000)
const asset = Asset.from(price, '4,EOS')
assert.equal(String(asset), '0.0910 EOS')
assert.equal(asset.value, 0.091)
assert.equal(Number(asset.units), 910)
assert.equal(String(asset), '0.0671 EOS')
assert.equal(asset.value, 0.0671)
assert.equal(Number(asset.units), 671)
})
test('rex.price_per(10000)', async function () {
const rex = await resources.v1.rex.get_state()
@@ -51,9 +46,9 @@ suite('[eos] rex calculations', function () {
const price = rex.price_per(usage, 10000)
const asset = Asset.from(price, '4,EOS')
assert.equal(String(asset), '0.9098 EOS')
assert.equal(asset.value, 0.9098)
assert.equal(Number(asset.units), 9098)
assert.equal(String(asset), '0.6709 EOS')
assert.equal(asset.value, 0.6709)
assert.equal(Number(asset.units), 6709)
})
test('rex.price_per(1000000)', async function () {
const rex = await resources.v1.rex.get_state()
@@ -61,8 +56,8 @@ suite('[eos] rex calculations', function () {
const price = rex.price_per(usage, 1000000)
const asset = Asset.from(price, '4,EOS')
assert.equal(String(asset), '90.9765 EOS')
assert.equal(asset.value, 90.9765)
assert.equal(Number(asset.units), 909765)
assert.equal(String(asset), '67.0870 EOS')
assert.equal(asset.value, 67.087)
assert.equal(Number(asset.units), 670870)
})
})
+65 -4
View File
@@ -348,17 +348,73 @@
resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44"
integrity sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==
"@wharfkit/antelope@^0.7.3":
version "0.7.3"
resolved "https://registry.yarnpkg.com/@wharfkit/antelope/-/antelope-0.7.3.tgz#408f6c587f4f5990d4b55596c10be2e976798641"
integrity sha512-pyUmuXUpLQh1RVpJVIcbVUHTwV/DQ+MI0nlfWDBHIICdYf6XidZtQmaHB7JEXiFzlS8T7S9Xc5VOTOQU8dnl3Q==
"@wharfkit/abicache@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@wharfkit/abicache/-/abicache-1.2.0.tgz#f67f7bbd854adc443c3e363d5fbe3d27ac4f8383"
integrity sha512-1+564ODM1KhUs7chE8KpYhnxShuPLC1MvqYcXVuLosxXXwcYC4IiJ1V3VuikLG+xfBDp1GZivGjHQwv1awE2Zw==
dependencies:
"@wharfkit/antelope" "^1.0.0"
"@wharfkit/signing-request" "^3.1.0"
pako "^2.0.4"
tslib "^2.1.0"
"@wharfkit/antelope@^1.0.0":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@wharfkit/antelope/-/antelope-1.0.0.tgz#c3057b70575991be5de3aea19e0c474614783c80"
integrity sha512-gwc6L3AzceN/menx9HCV22Ekd3it1wRruY6dIkyfCaV2UBGmfvIVJ3wPaDi4Ppj2k50b86ShSSHdd52jOFd+dg==
dependencies:
bn.js "^4.11.9"
brorand "^1.1.0"
elliptic "^6.5.4"
hash.js "^1.0.0"
pako "^2.1.0"
tslib "^2.0.3"
"@wharfkit/common@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@wharfkit/common/-/common-1.2.0.tgz#147f783f2ba5cc6fa7dd75863ba98dd05880a9aa"
integrity sha512-me/BN8D/4UPkY7yt+4v+E/z62PVj4VKY5+iRb7zoWv0epbW4o4nC6Oer8kBVL7xWC6Guucaol3hkxkTMgrnwlQ==
dependencies:
tslib "^2.1.0"
"@wharfkit/mock-data@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@wharfkit/mock-data/-/mock-data-1.2.0.tgz#fa5749f1332e413ecd4126dedf1d17724840df41"
integrity sha512-R779GKbzVeJFvO/VMLnjSua4YteQiuJ1WX/MjEeo2ftP0aPgaLNEoFKGa7veAvYEv/6mgEcS4Sm5gyFi1Enxhg==
dependencies:
"@wharfkit/antelope" "^1.0.0"
"@wharfkit/session" "^1.1.0-rcfinal"
"@wharfkit/wallet-plugin-privatekey" "^1.0.0"
node-fetch "^2.6.1"
tslib "^2.1.0"
"@wharfkit/session@^1.1.0-rcfinal":
version "1.1.0-rcfinal"
resolved "https://registry.yarnpkg.com/@wharfkit/session/-/session-1.1.0-rcfinal.tgz#29a9f40dca8557e96d5e44c1498b09eb641f47e1"
integrity sha512-UijDlP2yE8WoprAXz8EpAyz1GyxWv9OloRGApTUKM/lMuSk1U2d7vefQzyXTn14f1npd7bfBzeTQ5piTerBHww==
dependencies:
"@wharfkit/abicache" "^1.2.0"
"@wharfkit/antelope" "^1.0.0"
"@wharfkit/common" "^1.2.0"
"@wharfkit/signing-request" "^3.1.0"
pako "^2.0.4"
tslib "^2.1.0"
"@wharfkit/signing-request@^3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@wharfkit/signing-request/-/signing-request-3.1.0.tgz#7883f0b2350c6fe3446d2b8733dd7d0004f01911"
integrity sha512-aVWV9Z3o77uDrFSR3wC78c1e/QNkfi3IxZbGzMizvoYTYPKHgHs1F6Go/1oe0Dlo/kEB9tgckFviccUqrK987w==
dependencies:
"@wharfkit/antelope" "^1.0.0"
tslib "^2.0.3"
"@wharfkit/wallet-plugin-privatekey@^1.0.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@wharfkit/wallet-plugin-privatekey/-/wallet-plugin-privatekey-1.1.0.tgz#5985bff61895c54d2afbef359cd42da4f3871c7d"
integrity sha512-45LPj7AOVDm4RugDEhy0fnQX/BcMffeJPjGUCUrLazJ2S0Sti8nNk4nqiJqyme84c/0gq7d65vvwlmVfGtPVEg==
dependencies:
tslib "^2.1.0"
acorn-jsx@^5.3.1:
version "5.3.1"
resolved "https://registry.yarnpkg.com/acorn-jsx/-/acorn-jsx-5.3.1.tgz#fc8661e11b7ac1539c47dbfea2e72b3af34d267b"
@@ -1986,6 +2042,11 @@ package-hash@^4.0.0:
lodash.flattendeep "^4.4.0"
release-zalgo "^1.0.0"
pako@^2.0.4, pako@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/pako/-/pako-2.1.0.tgz#266cc37f98c7d883545d11335c00fbd4062c9a86"
integrity sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==
parent-module@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2"