@steemit/steem-js 0.7.11 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/README.md +203 -87
  2. package/dist/api/index.d.ts +128 -0
  3. package/dist/api/methods.d.ts +9 -0
  4. package/dist/api/rpc-auth.d.ts +43 -0
  5. package/dist/api/transports/base.d.ts +13 -0
  6. package/dist/api/transports/http.d.ts +9 -0
  7. package/dist/api/transports/index.d.ts +9 -0
  8. package/dist/api/transports/types.d.ts +35 -0
  9. package/dist/api/transports/ws.d.ts +18 -0
  10. package/dist/auth/ecc/index.d.ts +9 -0
  11. package/dist/auth/ecc/src/address.d.ts +13 -0
  12. package/dist/auth/ecc/src/aes.d.ts +16 -0
  13. package/dist/auth/ecc/src/brain_key.d.ts +1 -0
  14. package/dist/auth/ecc/src/ecdsa.d.ts +28 -0
  15. package/dist/auth/ecc/src/ecsignature.d.ts +19 -0
  16. package/dist/auth/ecc/src/enforce_types.d.ts +5 -0
  17. package/dist/auth/ecc/src/hash.d.ts +25 -0
  18. package/dist/auth/ecc/src/index.d.ts +9 -0
  19. package/dist/auth/ecc/src/key_private.d.ts +38 -0
  20. package/dist/auth/ecc/src/key_public.d.ts +41 -0
  21. package/dist/auth/ecc/src/key_utils.d.ts +9 -0
  22. package/dist/auth/ecc/src/signature.d.ts +18 -0
  23. package/dist/auth/ecc.d.ts +3 -0
  24. package/dist/auth/index.d.ts +48 -0
  25. package/dist/auth/key_classes.d.ts +3 -0
  26. package/dist/auth/serializer.d.ts +19 -0
  27. package/dist/broadcast/helpers.d.ts +11 -0
  28. package/dist/broadcast/index.d.ts +43 -0
  29. package/dist/broadcast/operations.d.ts +6 -0
  30. package/dist/config.d.ts +25 -0
  31. package/dist/crypto/index.d.ts +25 -0
  32. package/dist/formatter/index.d.ts +92 -0
  33. package/dist/index.cjs +25848 -0
  34. package/dist/index.cjs.map +1 -0
  35. package/dist/index.d.ts +30 -0
  36. package/dist/index.js +25812 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/index.umd.js +57513 -0
  39. package/dist/index.umd.js.map +1 -0
  40. package/dist/memo/index.d.ts +11 -0
  41. package/dist/operations/index.d.ts +44 -0
  42. package/dist/serializer/convert.d.ts +12 -0
  43. package/dist/serializer/index.d.ts +11 -0
  44. package/dist/serializer/number_utils.d.ts +8 -0
  45. package/dist/serializer/precision.d.ts +5 -0
  46. package/dist/serializer/types.d.ts +36 -0
  47. package/dist/types/index.d.ts +131 -0
  48. package/dist/types.d.ts +34 -0
  49. package/dist/utils/index.d.ts +8 -0
  50. package/dist/utils.d.ts +2 -0
  51. package/package.json +72 -67
  52. package/.circleci/config.yml +0 -23
  53. package/.dockerignore +0 -12
  54. package/.editorconfig +0 -20
  55. package/.eslintrc +0 -27
  56. package/LICENSE +0 -21
  57. package/circle.yml +0 -3
  58. package/config.json +0 -10
  59. package/dist/statistics.html +0 -208
  60. package/dist/steem-tests.min.js +0 -23
  61. package/dist/steem-tests.min.js.gz +0 -0
  62. package/dist/steem-tests.min.js.map +0 -1
  63. package/dist/steem.min.js +0 -18
  64. package/dist/steem.min.js.gz +0 -0
  65. package/dist/steem.min.js.map +0 -1
  66. package/lib/api/index.js +0 -422
  67. package/lib/api/methods.js +0 -413
  68. package/lib/api/transports/base.js +0 -72
  69. package/lib/api/transports/http.js +0 -172
  70. package/lib/api/transports/index.js +0 -20
  71. package/lib/api/transports/ws.js +0 -228
  72. package/lib/auth/ecc/README.md +0 -20
  73. package/lib/auth/ecc/index.js +0 -13
  74. package/lib/auth/ecc/package.json +0 -36
  75. package/lib/auth/ecc/src/address.js +0 -84
  76. package/lib/auth/ecc/src/aes.js +0 -184
  77. package/lib/auth/ecc/src/brain_key.js +0 -13
  78. package/lib/auth/ecc/src/ecdsa.js +0 -219
  79. package/lib/auth/ecc/src/ecsignature.js +0 -128
  80. package/lib/auth/ecc/src/enforce_types.js +0 -49
  81. package/lib/auth/ecc/src/hash.js +0 -67
  82. package/lib/auth/ecc/src/key_private.js +0 -212
  83. package/lib/auth/ecc/src/key_public.js +0 -215
  84. package/lib/auth/ecc/src/key_utils.js +0 -112
  85. package/lib/auth/ecc/src/signature.js +0 -187
  86. package/lib/auth/index.js +0 -126
  87. package/lib/auth/memo.js +0 -147
  88. package/lib/auth/serializer/README.md +0 -13
  89. package/lib/auth/serializer/index.js +0 -21
  90. package/lib/auth/serializer/package.json +0 -32
  91. package/lib/auth/serializer/src/ChainTypes.js +0 -90
  92. package/lib/auth/serializer/src/convert.js +0 -37
  93. package/lib/auth/serializer/src/error_with_cause.js +0 -42
  94. package/lib/auth/serializer/src/fast_parser.js +0 -77
  95. package/lib/auth/serializer/src/number_utils.js +0 -67
  96. package/lib/auth/serializer/src/object_id.js +0 -68
  97. package/lib/auth/serializer/src/operations.js +0 -787
  98. package/lib/auth/serializer/src/precision.js +0 -95
  99. package/lib/auth/serializer/src/serializer.js +0 -211
  100. package/lib/auth/serializer/src/template.js +0 -17
  101. package/lib/auth/serializer/src/types.js +0 -1238
  102. package/lib/auth/serializer/src/validation.js +0 -360
  103. package/lib/broadcast/helpers.js +0 -177
  104. package/lib/broadcast/index.js +0 -127
  105. package/lib/broadcast/operations.js +0 -255
  106. package/lib/browser.js +0 -29
  107. package/lib/config.js +0 -45
  108. package/lib/formatter.js +0 -189
  109. package/lib/index.js +0 -19
  110. package/lib/utils.js +0 -55
  111. package/node-4.dockerfile +0 -6
  112. package/node-6.dockerfile +0 -6
  113. package/test/Crypto.js +0 -100
  114. package/test/KeyFormats.js +0 -105
  115. package/test/all_types.js +0 -115
  116. package/test/api.test.js +0 -326
  117. package/test/broadcast.test.js +0 -225
  118. package/test/browser/BrowserTests.js +0 -55
  119. package/test/comment.test.js +0 -69
  120. package/test/hf20-accounts.test.js +0 -76
  121. package/test/hf21-sps.test.js +0 -78
  122. package/test/memo.test.js +0 -37
  123. package/test/number_utils.js +0 -28
  124. package/test/operations_test.js +0 -39
  125. package/test/smt.test.js +0 -347
  126. package/test/test-post.json +0 -13
  127. package/test/test.html +0 -13
  128. package/test/test_helper.js +0 -19
  129. package/test/types_test.js +0 -139
  130. package/webpack/makeConfig.js +0 -105
  131. package/webpack.config.js +0 -2
  132. package/yarn.lock +0 -3336
package/test/Crypto.js DELETED
@@ -1,100 +0,0 @@
1
- import config from "../src/config"
2
- import { Aes, PrivateKey, PublicKey, Signature } from "../src/auth/ecc"
3
- import assert from "assert"
4
-
5
- var secureRandom = require('secure-random');
6
- var hash = require('../src/auth/ecc/src/hash');
7
- var key = require('../src/auth/ecc/src/key_utils');
8
-
9
- describe("steem.auth: Crypto", function() {
10
-
11
- /*it "Computes public key", ->
12
- private_key = PrivateKey.fromHex decrypted_key.substring 0, 64
13
- public_key = private_key.toPublicKey()
14
- console.log public_key.toHex());*/
15
-
16
- it("sign", function() {
17
- this.timeout(10000);
18
- var private_key = PrivateKey.fromSeed("1");
19
- return (() => {
20
- var result = [];
21
- for (var i = 0; i < 10; i++) {
22
- result.push(Signature.signBuffer((new Buffer(i)), private_key));
23
- }
24
- return result;
25
- })();
26
- });
27
-
28
- })
29
-
30
- describe("steem.auth: derives", ()=> {
31
-
32
- let prefix = config.get("address_prefix")
33
- let one_time_private = PrivateKey.fromHex("8fdfdde486f696fd7c6313325e14d3ff0c34b6e2c390d1944cbfe150f4457168")
34
- let to_public = PublicKey.fromStringOrThrow(prefix + "7vbxtK1WaZqXsiCHPcjVFBewVj8HFRd5Z5XZDpN6Pvb2dZcMqK")
35
- let secret = one_time_private.get_shared_secret( to_public )
36
- let child = hash.sha256( secret )
37
-
38
- // Check everything above with `wdump((child));` from the witness_node:
39
- assert.equal(child.toString('hex'), "1f296fa48172d9af63ef3fb6da8e369e6cc33c1fb7c164207a3549b39e8ef698")
40
-
41
- let nonce = hash.sha256( one_time_private.toBuffer() )
42
- assert.equal(nonce.toString('hex'), "462f6c19ece033b5a3dba09f1e1d7935a5302e4d1eac0a84489cdc8339233fbf")
43
-
44
- it("child from public", ()=> assert.equal(
45
- to_public.child(child).toString(),
46
- "STM6XA72XARQCain961PCJnXiKYdEMrndNGago2PV5bcUiVyzJ6iL",
47
- "derive child public key"
48
- ))
49
-
50
- // child = hash.sha256( one_time_private.get_secret( to_public ))
51
- it("child from private", ()=> assert.equal(
52
- PrivateKey.fromSeed("alice-brain-key").child(child).toPublicKey().toString(),
53
- "STM6XA72XARQCain961PCJnXiKYdEMrndNGago2PV5bcUiVyzJ6iL",
54
- "derive child from private key"
55
- ))
56
-
57
- // "many keys" works, not really needed
58
- // it("many keys", function() {
59
- //
60
- // this.timeout(10 * 1000)
61
- //
62
- // for (var i = 0; i < 10; i++) {
63
- // let privkey1 = key.get_random_key()
64
- // let privkey2 = key.get_random_key()
65
- //
66
- // let secret1 = one_time_private.get_shared_secret( privkey1.toPublicKey() )
67
- // let child1 = hash.sha256( secret1 )
68
- //
69
- // let secret2 = privkey2.get_shared_secret( privkey2.toPublicKey() )
70
- // let child2 = hash.sha256( secret2 )
71
- //
72
- // it("child from public", ()=> assert.equal(
73
- // privkey1.toPublicKey().child(child1).toString(),
74
- // privkey2.toPublicKey().child(child2).toString(),
75
- // "derive child public key"
76
- // ))
77
- //
78
- // it("child from private", ()=> assert.equal(
79
- // privkey1.child(child1).toString(),
80
- // privkey2.child(child2).toString(),
81
- // "derive child private key"
82
- // ))
83
- // }
84
- //
85
- // })
86
-
87
- })
88
-
89
- var min_time_elapsed = function(f){
90
- var start_t = Date.now();
91
- var ret = f();
92
- var elapsed = Date.now() - start_t;
93
- assert.equal(
94
- // repeat operations may take less time
95
- elapsed >= 250 * 0.8, true,
96
- `minimum time requirement was not met, instead only ${elapsed/1000.0} elapsed`
97
- );
98
- return ret;
99
- };
100
-
@@ -1,105 +0,0 @@
1
- import { PrivateKey, PublicKey, Address } from "../src/auth/ecc";
2
- import assert from "assert"
3
-
4
- var test = function(key) {
5
- describe("steem.auth: key_formats", function() {
6
-
7
- it("Calcualtes public key from private key", function() {
8
- var private_key = PrivateKey.fromHex(key.private_key);
9
- var public_key = private_key.toPublicKey();
10
- assert.equal(key.public_key, public_key.toPublicKeyString());
11
- });
12
-
13
- it("Create BTS short address", function() {
14
- var public_key = PublicKey.fromString(key.public_key);
15
- assert.equal(key.bts_address, public_key.toAddressString());
16
- })
17
-
18
- it("Blockchain Address", function() {
19
- var public_key = PublicKey.fromString(key.public_key);
20
- assert.equal(key.blockchain_address, public_key.toBlockchainAddress().toString('hex'));
21
- });
22
-
23
- it("BTS public key import / export", function() {
24
- var public_key = PublicKey.fromString(key.public_key);
25
- assert.equal(key.public_key, public_key.toPublicKeyString());
26
- });
27
-
28
- it("PTS", function() {
29
- var private_key = PrivateKey.fromHex(key.private_key);
30
- var public_key = private_key.toPublicKey();
31
- assert.equal(key.pts_address, public_key.toPtsAddy());
32
- });
33
-
34
- it("To WIF", function() {
35
- var private_key = PrivateKey.fromHex(key.private_key);
36
- assert.equal(key.private_key_WIF_format, private_key.toWif());
37
- });
38
-
39
- it("From WIF", function() {
40
- var private_key = PrivateKey.fromWif(key.private_key_WIF_format);
41
- assert.equal(private_key.toHex(), key.private_key);
42
- });
43
-
44
- it("Calc public key", function() {
45
- var private_key = PrivateKey.fromHex(key.private_key);
46
- var public_key = private_key.toPublicKey();
47
- assert.equal(key.bts_address, public_key.toAddressString());
48
- });
49
-
50
- it("BTS/BTC uncompressed", function() {
51
- var public_key = PublicKey.fromString(key.public_key);
52
- var address = Address.fromPublic(public_key, false, 0);
53
- assert.equal(key.Uncompressed_BTC, address.toString());
54
- });
55
-
56
- it("BTS/BTC compressed", function() {
57
- var public_key = PublicKey.fromString(key.public_key);
58
- var address = Address.fromPublic(public_key, true, 0);
59
- assert.equal(key.Compressed_BTC, address.toString());
60
- });
61
-
62
- it("BTS/PTS uncompressed", function() {
63
- var public_key = PublicKey.fromString(key.public_key);
64
- var address = Address.fromPublic(public_key, false, 56);
65
- assert.equal(key.Uncompressed_PTS, address.toString());
66
- });
67
-
68
- it("BTS/PTS compressed", function() {
69
- var public_key = PublicKey.fromString(key.public_key);
70
- var address = Address.fromPublic(public_key, true, 56);
71
- assert.equal(key.Compressed_PTS, address.toString());
72
- });
73
-
74
- it("null hex to pubkey", function() {
75
- var public_key = PublicKey.fromHex(key.null_hex);
76
- assert.equal(key.null_address, public_key.toPublicKeyString());
77
- });
78
-
79
- it("null pubkey to hex", function() {
80
- var public_key = PublicKey.fromString(key.null_address);
81
- assert.equal(key.null_hex, public_key.toHex());
82
- });
83
- });
84
- };
85
-
86
- test({
87
- // delegate0
88
- // sourced from: ./bitshares/programs/utils/bts_create_key
89
- public_key: "STM7jDPoMwyjVH5obFmqzFNp4Ffp7G2nvC7FKFkrMBpo7Sy4uq5Mj",
90
- private_key: "20991828d456b389d0768ed7fb69bf26b9bb87208dd699ef49f10481c20d3e18",
91
- private_key_WIF_format: "5J4eFhjREJA7hKG6KcvHofHMXyGQZCDpQE463PAaKo9xXY6UDPq",
92
- bts_address: "STM8DvGQqzbgCR5FHiNsFf8kotEXr8VKD3mR",
93
- pts_address: "Po3mqkgMzBL4F1VXJArwQxeWf3fWEpxUf3",
94
- encrypted_private_key: "5e1ae410919c450dce1c476ae3ed3e5fe779ad248081d85b3dcf2888e698744d0a4b60efb7e854453bec3f6883bcbd1d",
95
- blockchain_address: "4f3a560442a05e4fbb257e8dc5859b736306bace",
96
- // https://github.com/BitShares/bitshares/blob/2602504998dcd63788e106260895769697f62b07/libraries/wallet/wallet_db.cpp#L103-L108
97
- Uncompressed_BTC: "STMLAFmEtM8as1mbmjVcj5dphLdPguXquimn",
98
- Compressed_BTC: "STMANNTSEaUviJgWLzJBersPmyFZBY4jJETY",
99
- Uncompressed_PTS: "STMEgj7RM6FBwSoccGaESJLC3Mi18785bM3T",
100
- Compressed_PTS: "STMD5rYtofD6D4UHJH6mo953P5wpBfMhdMEi",
101
- // https://github.com/steemit/steem-js/issues/267
102
- null_hex: "000000000000000000000000000000000000000000000000000000000000000000",
103
- null_address: "STM1111111111111111111111111111111114T1Anm"
104
- });
105
-
package/test/all_types.js DELETED
@@ -1,115 +0,0 @@
1
- import { PrivateKey, PublicKey, Address } from "../src/auth/ecc"
2
- var assert = require('assert');
3
- var Serilizer = require("../src/auth/serializer/src/serializer")
4
- var types = require('../src/auth/serializer/src/types');
5
- var ops = require('../src/auth/serializer/src/operations');
6
-
7
- var {
8
- //varint32,
9
- uint8, uint16, uint32, int16, int64, uint64,
10
- string, string_binary, bytes, bool, array, fixed_array,
11
- protocol_id_type, object_id_type, vote_id,
12
- // future_extensions,
13
- static_variant, map, set,
14
- public_key, address,
15
- time_point_sec,
16
- optional,
17
- asset
18
- } = types
19
-
20
- var { price, transfer } = ops
21
-
22
- // Must stay in sync with allTypes below.
23
- let AllTypes = new Serilizer("all_types", {
24
- uint8, uint16, uint32, int16, int64, uint64,
25
- string, string_binary, bytes: bytes(1), bool, array: array(uint8), fixed_array: fixed_array(2, uint8),
26
- protocol_id_type: protocol_id_type("base"), object_id_type, //vote_id,
27
-
28
- static_variant: array(static_variant( [transfer, price] )),
29
- map: map(uint8, uint8),
30
- set: set(uint8),
31
-
32
- public_key, address,
33
-
34
- time_optional: optional( time_point_sec ),
35
- time_point_sec1: time_point_sec,
36
- time_point_sec2: time_point_sec,
37
- time_point_sec3: time_point_sec,
38
- })
39
-
40
- // Must stay in sync with AllTypes above.
41
- let allTypes = {
42
-
43
- uint8: Math.pow(2,8)-1, uint16: Math.pow(2,16)-1, uint32: Math.pow(2,32)-1,
44
- int16: 30000, int64: "9223372036854775807", uint64: "9223372036854775807",
45
-
46
- string: "‘Quote’", string_binary: '\u0001', bytes: "ff", bool: true, array: [2, 1], fixed_array: [1, 0],
47
- protocol_id_type: "1.1.1", object_id_type: "1.1.1", //vote_id: "2:1",
48
-
49
- static_variant: [
50
- ["transfer", {from:"alice", to:"bob", amount: "1.000 STEEM", memo: ""}],
51
- ["price", {base: "1.000 STEEM", quote: "1.000 STEEM"}],
52
- ],
53
-
54
- map: [[4,3], [2,1]],
55
- set: [2,1],
56
-
57
- public_key: PrivateKey.fromSeed("").toPublicKey().toString(),
58
- address: Address.fromPublic(PrivateKey.fromSeed("").toPublicKey()).toString(),
59
-
60
- time_optional: undefined,
61
- time_point_sec1: new Date(),
62
- time_point_sec2: Math.floor(Date.now()/1000),
63
- time_point_sec3: '2017-02-16T20:27:12',
64
- }
65
-
66
- describe("steem.auth: all types", ()=> {
67
-
68
- let { toObject, fromObject, toBuffer, fromBuffer } = AllTypes
69
-
70
- toObject = toObject.bind(AllTypes)
71
- fromObject = fromObject.bind(AllTypes)
72
- toBuffer = toBuffer.bind(AllTypes)
73
- fromBuffer = fromBuffer.bind(AllTypes)
74
-
75
- it("from object", ()=> {
76
- assert(fromObject(allTypes), "serializable" )
77
- assert(fromObject(fromObject(allTypes)), "non-serializable")
78
- })
79
-
80
- it("to object", ()=> {
81
- assert(toObject(allTypes), "serializable" )
82
- assert.deepEqual(toObject(allTypes), toObject(allTypes), "serializable (single to)" )
83
- assert.deepEqual(toObject(toObject(allTypes)), toObject(allTypes), "serializable (double to)" )
84
- assert.deepEqual(toObject(fromObject(allTypes)), toObject(allTypes), "non-serializable" )
85
- assert.deepEqual(toObject(fromObject(fromObject(allTypes))), toObject(allTypes), "non-serializable (double from)")
86
- })
87
-
88
- it("to buffer", ()=>{
89
- assert(toBuffer(allTypes), "serializable" )
90
- assert(toBuffer(fromObject(allTypes)), "non-serializable")
91
- assert.equal(
92
- toBuffer( allTypes ).toString("hex"), // serializable
93
- toBuffer( fromObject( allTypes )).toString("hex"), // non-serializable
94
- "serializable and non-serializable"
95
- )
96
- })
97
-
98
- it("from buffer", ()=> {
99
- assert.deepEqual(toObject(fromBuffer(toBuffer(allTypes))), toObject(allTypes), "serializable" )
100
- assert.deepEqual(toObject(fromBuffer(toBuffer(fromObject(allTypes)))), toObject(allTypes), "non-serializable" )
101
- })
102
-
103
- it("template", ()=> {
104
- assert(toObject(allTypes, {use_default: true}))
105
- assert(toObject(allTypes, {annotate: true}))
106
- assert(toObject({}, {use_default: true}))
107
- assert(toObject({}, {use_default: true, annotate: true}))
108
- })
109
-
110
- // keep last
111
- it("visual check", ()=> {
112
- console.log(toObject(fromObject(allTypes)))
113
- })
114
-
115
- })
package/test/api.test.js DELETED
@@ -1,326 +0,0 @@
1
- require('babel-polyfill');
2
- import assert from 'assert';
3
- import should from 'should';
4
- import testPost from './test-post.json';
5
- import steem from '../src';
6
- import api from '../src/api';
7
-
8
- describe('steem.api:', function () {
9
- this.timeout(30 * 1000);
10
-
11
- describe('setOptions', () => {
12
- it('works', () => {
13
- let url = steem.config.get('uri');
14
- if(! url) url = steem.config.get('websocket');
15
- steem.api.setOptions({ url: url, useAppbaseApi: true });
16
- });
17
- });
18
-
19
- describe('getFollowers', () => {
20
- describe('getting ned\'s followers', () => {
21
- it('works', async () => {
22
- const result = await steem.api.getFollowersAsync('ned', 0, 'blog', 5);
23
- assert(result, 'getFollowersAsync resoved to null?');
24
- result.should.have.lengthOf(5);
25
- });
26
-
27
- it('the startFollower parameter has an impact on the result', async () => {
28
- // Get the first 5
29
- const result1 = await steem.api.getFollowersAsync('ned', 0, 'blog', 5)
30
- result1.should.have.lengthOf(5);
31
- const result2 = await steem.api.getFollowersAsync('ned', result1[result1.length - 1].follower, 'blog', 5)
32
- result2.should.have.lengthOf(5);
33
- result1.should.not.be.eql(result2);
34
- });
35
-
36
- it('clears listeners', async () => {
37
- steem.api.listeners('message').should.have.lengthOf(0);
38
- });
39
- });
40
- });
41
-
42
- describe('getContent', () => {
43
- describe('getting a random post', () => {
44
- it('works', async () => {
45
- const result = await steem.api.getContentAsync('yamadapc', 'test-1-2-3-4-5-6-7-9');
46
- result.should.have.properties(testPost);
47
- });
48
-
49
- it('clears listeners', async () => {
50
- steem.api.listeners('message').should.have.lengthOf(0);
51
- });
52
- });
53
- });
54
-
55
- describe('streamBlockNumber', () => {
56
- it('streams steem transactions', (done) => {
57
- let i = 0;
58
- const release = steem.api.streamBlockNumber((err, block) => {
59
- should.exist(block);
60
- block.should.be.instanceOf(Number);
61
- i++;
62
- if (i === 2) {
63
- release();
64
- done();
65
- }
66
- });
67
- });
68
- });
69
-
70
- describe('streamBlock', () => {
71
- it('streams steem blocks', (done) => {
72
- let i = 0;
73
- const release = steem.api.streamBlock((err, block) => {
74
- try {
75
- should.exist(block);
76
- block.should.have.properties([
77
- 'previous',
78
- 'transactions',
79
- 'timestamp',
80
- ]);
81
- } catch (err2) {
82
- release();
83
- done(err2);
84
- return;
85
- }
86
-
87
- i++;
88
- if (i === 2) {
89
- release();
90
- done();
91
- }
92
- });
93
- });
94
- });
95
-
96
- describe('streamTransactions', () => {
97
- it('streams steem transactions', (done) => {
98
- let i = 0;
99
- const release = steem.api.streamTransactions((err, transaction) => {
100
- try {
101
- should.exist(transaction);
102
- transaction.should.have.properties([
103
- 'ref_block_num',
104
- 'operations',
105
- 'extensions',
106
- ]);
107
- } catch (err2) {
108
- release();
109
- done(err2);
110
- return;
111
- }
112
-
113
- i++;
114
- if (i === 2) {
115
- release();
116
- done();
117
- }
118
- });
119
- });
120
- });
121
-
122
- describe('streamOperations', () => {
123
- it('streams steem operations', (done) => {
124
- let i = 0;
125
- const release = steem.api.streamOperations((err, operation) => {
126
- try {
127
- should.exist(operation);
128
- } catch (err2) {
129
- release();
130
- done(err2);
131
- return;
132
- }
133
-
134
- i++;
135
- if (i === 2) {
136
- release();
137
- done();
138
- }
139
- });
140
- });
141
- });
142
-
143
- describe('useApiOptions', () => {
144
- it('works ok with the prod instances', async() => {
145
- steem.api.setOptions({ useAppbaseApi: true, url: steem.config.get('uri') });
146
-
147
- const result = await steem.api.getContentAsync('yamadapc', 'test-1-2-3-4-5-6-7-9');
148
- steem.api.setOptions({ useAppbaseApi: false, url: steem.config.get('uri') });
149
-
150
- result.should.have.properties(testPost);
151
- });
152
- });
153
-
154
- describe('with retry', () => {
155
- let steemApi;
156
- beforeEach(() => {
157
- steemApi = new api.Steem({});
158
- });
159
-
160
- it('works by default', async function() {
161
- let attempts = 0;
162
- steemApi.setOptions({
163
- url: 'https://api.steemit.com',
164
- fetchMethod: (uri, req) => new Promise((res, rej) => {
165
- const data = JSON.parse(req.body);
166
- res({
167
- ok: true,
168
- json: () => Promise.resolve({
169
- jsonrpc: '2.0',
170
- id: data.id,
171
- result: ['ned'],
172
- }),
173
- });
174
- attempts++;
175
- }),
176
- });
177
- const result = await steemApi.getFollowersAsync('ned', 0, 'blog', 5)
178
- assert.equal(attempts, 1);
179
- assert.deepEqual(result, ['ned']);
180
- });
181
-
182
- it('does not retry by default', async() => {
183
- let attempts = 0;
184
- steemApi.setOptions({
185
- url: 'https://api.steemit.com',
186
- fetchMethod: (uri, req) => new Promise((res, rej) => {
187
- rej(new Error('Bad request'));
188
- attempts++;
189
- }),
190
- });
191
-
192
- let result;
193
- let errored = false;
194
- try {
195
- result = await steemApi.getFollowersAsync('ned', 0, 'blog', 5)
196
- } catch (e) {
197
- errored = true;
198
- }
199
- assert.equal(attempts, 1);
200
- assert.equal(errored, true);
201
- });
202
-
203
- it('works with retry passed as a boolean', async() => {
204
- let attempts = 0;
205
- steemApi.setOptions({
206
- url: 'https://api.steemit.com',
207
- fetchMethod: (uri, req) => new Promise((res, rej) => {
208
- const data = JSON.parse(req.body);
209
- res({
210
- ok: true,
211
- json: () => Promise.resolve({
212
- jsonrpc: '2.0',
213
- id: data.id,
214
- result: ['ned'],
215
- }),
216
- });
217
- attempts++;
218
- }),
219
- });
220
-
221
- const result = await steemApi.getFollowersAsync('ned', 0, 'blog', 5)
222
- assert.equal(attempts, 1);
223
- assert.deepEqual(result, ['ned']);
224
- });
225
-
226
- it('retries with retry passed as a boolean', async() => {
227
- let attempts = 0;
228
- steemApi.setOptions({
229
- url: 'https://api.steemit.com',
230
- retry: true,
231
- fetchMethod: (uri, req) => new Promise((res, rej) => {
232
- if (attempts < 1) {
233
- rej(new Error('Bad request'));
234
- } else {
235
- const data = JSON.parse(req.body);
236
- res({
237
- ok: true,
238
- json: () => Promise.resolve({
239
- jsonrpc: '2.0',
240
- id: data.id,
241
- result: ['ned'],
242
- }),
243
- });
244
- }
245
- attempts++;
246
- }),
247
- });
248
-
249
- let result;
250
- let errored = false;
251
- try {
252
- result = await steemApi.getFollowersAsync('ned', 0, 'blog', 5);
253
- } catch (e) {
254
- errored = true;
255
- }
256
- assert.equal(attempts, 2);
257
- assert.equal(errored, false);
258
- assert.deepEqual(result, ['ned']);
259
- });
260
-
261
- it('works with retry passed as an object', async() => {
262
- steemApi.setOptions({
263
- url: 'https://api.steemit.com',
264
- retry: {
265
- retries: 3,
266
- minTimeout: 1, // 1ms
267
- },
268
- fetchMethod: (uri, req) => new Promise((res, rej) => {
269
- const data = JSON.parse(req.body);
270
- res({
271
- ok: 'true',
272
- json: () => Promise.resolve({
273
- jsonrpc: '2.0',
274
- id: data.id,
275
- result: ['ned'],
276
- }),
277
- });
278
- }),
279
- });
280
-
281
- const result = await steemApi.getFollowersAsync('ned', 0, 'blog', 5);
282
- assert.deepEqual(result, ['ned']);
283
- });
284
-
285
- it('retries with retry passed as an object', async() => {
286
- let attempts = 0;
287
- steemApi.setOptions({
288
- url: 'https://api.steemit.com',
289
- retry: {
290
- retries: 3,
291
- minTimeout: 1,
292
- },
293
- fetchMethod: (uri, req) => new Promise((res, rej) => {
294
- if (attempts < 1) {
295
- rej(new Error('Bad request'));
296
- } else {
297
- const data = JSON.parse(req.body);
298
- res({
299
- ok: true,
300
- json: () => Promise.resolve({
301
- jsonrpc: '2.0',
302
- id: data.id,
303
- result: ['ned'],
304
- }),
305
- });
306
- }
307
- attempts++;
308
- }),
309
- });
310
-
311
- let result;
312
- let errored = false;
313
- try {
314
- result = await steemApi.getFollowersAsync('ned', 0, 'blog', 5);
315
- } catch (e) {
316
- errored = true;
317
- }
318
- assert.equal(attempts, 2);
319
- assert.equal(errored, false);
320
- assert.deepEqual(result, ['ned']);
321
- });
322
-
323
- it('does not retry non-retriable operations');
324
- });
325
-
326
- });