@steemit/steem-js 0.8.0 → 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 (126) hide show
  1. package/README.md +202 -105
  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 +68 -87
  52. package/.dockerignore +0 -12
  53. package/.editorconfig +0 -20
  54. package/.eslintrc +0 -27
  55. package/LICENSE +0 -21
  56. package/circle.yml +0 -3
  57. package/config.json +0 -10
  58. package/dist/steem-tests.min.js +0 -4097
  59. package/dist/steem.min.js +0 -2089
  60. package/docker-webpack.config.js +0 -44
  61. package/lib/api/index.js +0 -315
  62. package/lib/api/methods.js +0 -428
  63. package/lib/api/rpc-auth.js +0 -135
  64. package/lib/api/transports/base.js +0 -31
  65. package/lib/api/transports/http.js +0 -157
  66. package/lib/api/transports/index.js +0 -13
  67. package/lib/api/transports/ws.js +0 -128
  68. package/lib/auth/ecc/index.js +0 -13
  69. package/lib/auth/ecc/src/address.js +0 -54
  70. package/lib/auth/ecc/src/aes.js +0 -148
  71. package/lib/auth/ecc/src/brain_key.js +0 -13
  72. package/lib/auth/ecc/src/ecdsa.js +0 -193
  73. package/lib/auth/ecc/src/ecsignature.js +0 -102
  74. package/lib/auth/ecc/src/enforce_types.js +0 -42
  75. package/lib/auth/ecc/src/hash.js +0 -58
  76. package/lib/auth/ecc/src/key_private.js +0 -159
  77. package/lib/auth/ecc/src/key_public.js +0 -143
  78. package/lib/auth/ecc/src/key_utils.js +0 -70
  79. package/lib/auth/ecc/src/signature.js +0 -135
  80. package/lib/auth/index.js +0 -113
  81. package/lib/auth/memo.js +0 -119
  82. package/lib/auth/serializer/index.js +0 -15
  83. package/lib/auth/serializer/src/ChainTypes.js +0 -87
  84. package/lib/auth/serializer/src/convert.js +0 -34
  85. package/lib/auth/serializer/src/error_with_cause.js +0 -27
  86. package/lib/auth/serializer/src/fast_parser.js +0 -57
  87. package/lib/auth/serializer/src/number_utils.js +0 -43
  88. package/lib/auth/serializer/src/object_id.js +0 -43
  89. package/lib/auth/serializer/src/operations.js +0 -695
  90. package/lib/auth/serializer/src/precision.js +0 -77
  91. package/lib/auth/serializer/src/serializer.js +0 -165
  92. package/lib/auth/serializer/src/template.js +0 -22
  93. package/lib/auth/serializer/src/types.js +0 -1085
  94. package/lib/auth/serializer/src/validation.js +0 -300
  95. package/lib/broadcast/helpers.js +0 -140
  96. package/lib/broadcast/index.js +0 -106
  97. package/lib/broadcast/operations.js +0 -255
  98. package/lib/browser.js +0 -25
  99. package/lib/config.js +0 -23
  100. package/lib/formatter.js +0 -163
  101. package/lib/index.js +0 -21
  102. package/lib/utils.js +0 -50
  103. package/node-18.dockerfile +0 -28
  104. package/test/Crypto.js +0 -100
  105. package/test/KeyFormats.js +0 -105
  106. package/test/all_types.js +0 -115
  107. package/test/api.test.js +0 -363
  108. package/test/broadcast.test.js +0 -231
  109. package/test/browser/BrowserTests.js +0 -55
  110. package/test/comment.test.js +0 -83
  111. package/test/hf20-accounts.test.js +0 -76
  112. package/test/hf21-sps.test.js +0 -78
  113. package/test/memo.test.js +0 -37
  114. package/test/number_utils.js +0 -28
  115. package/test/operations_test.js +0 -39
  116. package/test/promise-broadcast.test.js +0 -86
  117. package/test/reputation.test.js +0 -68
  118. package/test/smt.test.js +0 -347
  119. package/test/test-post.json +0 -13
  120. package/test/test.html +0 -13
  121. package/test/test_helper.js +0 -19
  122. package/test/types_test.js +0 -139
  123. package/test-github-workflow.bat +0 -19
  124. package/test-github-workflow.sh +0 -15
  125. package/webpack/makeConfig.js +0 -113
  126. package/webpack.config.js +0 -2
@@ -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("Calculates 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,363 +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
- describe('getRC', () => {
327
- describe('getting a RC of an account', () => {
328
- it('works', async () => {
329
- const result = await steem.api.findRcAccountsAsync(["justinsunsteemit"]);
330
- result.should.have.properties("rc_accounts");
331
- result["rc_accounts"][0].should.have.properties("rc_manabar");
332
- });
333
- it('clears listeners', async () => {
334
- steem.api.listeners('message').should.have.lengthOf(0);
335
- });
336
- });
337
- });
338
-
339
- describe('getExpiringDelegations', () => {
340
- describe('getting expired delegation of an account', () => {
341
- it('works', async () => {
342
- const result = await steem.api.getExpiringVestingDelegationsAsync("justyy", "2004-01-02T00:11:22", 100);
343
- result.should.have.properties("length");
344
- });
345
- it('clears listeners', async () => {
346
- steem.api.listeners('message').should.have.lengthOf(0);
347
- });
348
- });
349
- });
350
-
351
- describe('Account Recovery', () => {
352
- describe('findChangeRecoveryAccountRequests', () => {
353
- it('works', async () => {
354
- const result = await steem.api.findChangeRecoveryAccountRequestsAsync(["justyy", "ety001"]);
355
- result.should.have.properties("requests");
356
- result.requests.should.have.properties("length");
357
- });
358
- it('clears listeners', async () => {
359
- steem.api.listeners('message').should.have.lengthOf(0);
360
- });
361
- });
362
- });
363
- });