hive-stream 3.0.2 → 3.0.3
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.
- package/DOCUMENTATION.md +50 -2
- package/README.md +44 -3
- package/dist/adapters/base.adapter.d.ts +5 -0
- package/dist/adapters/base.adapter.js +9 -0
- package/dist/adapters/base.adapter.js.map +1 -1
- package/dist/adapters/mongodb.adapter.d.ts +6 -6
- package/dist/adapters/mongodb.adapter.js +36 -21
- package/dist/adapters/mongodb.adapter.js.map +1 -1
- package/dist/adapters/postgresql.adapter.d.ts +7 -0
- package/dist/adapters/postgresql.adapter.js +46 -19
- package/dist/adapters/postgresql.adapter.js.map +1 -1
- package/dist/adapters/sqlite.adapter.d.ts +4 -0
- package/dist/adapters/sqlite.adapter.js +10 -0
- package/dist/adapters/sqlite.adapter.js.map +1 -1
- package/dist/api.d.ts +13 -3
- package/dist/api.js +96 -62
- package/dist/api.js.map +1 -1
- package/dist/config.d.ts +7 -1
- package/dist/config.js +7 -1
- package/dist/config.js.map +1 -1
- package/dist/contracts/auctionhouse.contract.d.ts +4 -0
- package/dist/contracts/auctionhouse.contract.js +234 -0
- package/dist/contracts/auctionhouse.contract.js.map +1 -0
- package/dist/contracts/booking.contract.d.ts +4 -0
- package/dist/contracts/booking.contract.js +225 -0
- package/dist/contracts/booking.contract.js.map +1 -0
- package/dist/contracts/bountyboard.contract.d.ts +4 -0
- package/dist/contracts/bountyboard.contract.js +233 -0
- package/dist/contracts/bountyboard.contract.js.map +1 -0
- package/dist/contracts/bundlemarketplace.contract.d.ts +4 -0
- package/dist/contracts/bundlemarketplace.contract.js +195 -0
- package/dist/contracts/bundlemarketplace.contract.js.map +1 -0
- package/dist/contracts/charitymatch.contract.d.ts +4 -0
- package/dist/contracts/charitymatch.contract.js +172 -0
- package/dist/contracts/charitymatch.contract.js.map +1 -0
- package/dist/contracts/coinflip.contract.js +7 -1
- package/dist/contracts/coinflip.contract.js.map +1 -1
- package/dist/contracts/crowdfund.contract.d.ts +4 -0
- package/dist/contracts/crowdfund.contract.js +290 -0
- package/dist/contracts/crowdfund.contract.js.map +1 -0
- package/dist/contracts/dcabot.contract.d.ts +4 -0
- package/dist/contracts/dcabot.contract.js +217 -0
- package/dist/contracts/dcabot.contract.js.map +1 -0
- package/dist/contracts/dice.contract.js +7 -1
- package/dist/contracts/dice.contract.js.map +1 -1
- package/dist/contracts/domainregistry.contract.d.ts +4 -0
- package/dist/contracts/domainregistry.contract.js +232 -0
- package/dist/contracts/domainregistry.contract.js.map +1 -0
- package/dist/contracts/exchange.contract.js +209 -168
- package/dist/contracts/exchange.contract.js.map +1 -1
- package/dist/contracts/fanclub.contract.d.ts +4 -0
- package/dist/contracts/fanclub.contract.js +193 -0
- package/dist/contracts/fanclub.contract.js.map +1 -0
- package/dist/contracts/giftcard.contract.d.ts +4 -0
- package/dist/contracts/giftcard.contract.js +158 -0
- package/dist/contracts/giftcard.contract.js.map +1 -0
- package/dist/contracts/grantrounds.contract.d.ts +4 -0
- package/dist/contracts/grantrounds.contract.js +265 -0
- package/dist/contracts/grantrounds.contract.js.map +1 -0
- package/dist/contracts/groupbuy.contract.d.ts +4 -0
- package/dist/contracts/groupbuy.contract.js +198 -0
- package/dist/contracts/groupbuy.contract.js.map +1 -0
- package/dist/contracts/helpers.d.ts +64 -0
- package/dist/contracts/helpers.js +159 -0
- package/dist/contracts/helpers.js.map +1 -0
- package/dist/contracts/insurancepool.contract.d.ts +4 -0
- package/dist/contracts/insurancepool.contract.js +281 -0
- package/dist/contracts/insurancepool.contract.js.map +1 -0
- package/dist/contracts/invoice.contract.d.ts +4 -0
- package/dist/contracts/invoice.contract.js +193 -0
- package/dist/contracts/invoice.contract.js.map +1 -0
- package/dist/contracts/launchpad.contract.d.ts +4 -0
- package/dist/contracts/launchpad.contract.js +225 -0
- package/dist/contracts/launchpad.contract.js.map +1 -0
- package/dist/contracts/lotto.contract.js +53 -37
- package/dist/contracts/lotto.contract.js.map +1 -1
- package/dist/contracts/multisigtreasury.contract.d.ts +4 -0
- package/dist/contracts/multisigtreasury.contract.js +245 -0
- package/dist/contracts/multisigtreasury.contract.js.map +1 -0
- package/dist/contracts/nft.contract.d.ts +1 -0
- package/dist/contracts/nft.contract.js +236 -192
- package/dist/contracts/nft.contract.js.map +1 -1
- package/dist/contracts/oraclebounty.contract.d.ts +4 -0
- package/dist/contracts/oraclebounty.contract.js +250 -0
- package/dist/contracts/oraclebounty.contract.js.map +1 -0
- package/dist/contracts/payroll.contract.d.ts +4 -0
- package/dist/contracts/payroll.contract.js +232 -0
- package/dist/contracts/payroll.contract.js.map +1 -0
- package/dist/contracts/paywall.contract.d.ts +4 -0
- package/dist/contracts/paywall.contract.js +185 -0
- package/dist/contracts/paywall.contract.js.map +1 -0
- package/dist/contracts/poll.contract.js +2 -0
- package/dist/contracts/poll.contract.js.map +1 -1
- package/dist/contracts/predictionmarket.contract.d.ts +4 -0
- package/dist/contracts/predictionmarket.contract.js +213 -0
- package/dist/contracts/predictionmarket.contract.js.map +1 -0
- package/dist/contracts/proposaltimelock.contract.d.ts +4 -0
- package/dist/contracts/proposaltimelock.contract.js +250 -0
- package/dist/contracts/proposaltimelock.contract.js.map +1 -0
- package/dist/contracts/questpass.contract.d.ts +4 -0
- package/dist/contracts/questpass.contract.js +214 -0
- package/dist/contracts/questpass.contract.js.map +1 -0
- package/dist/contracts/referral.contract.d.ts +4 -0
- package/dist/contracts/referral.contract.js +238 -0
- package/dist/contracts/referral.contract.js.map +1 -0
- package/dist/contracts/rental.contract.d.ts +4 -0
- package/dist/contracts/rental.contract.js +221 -0
- package/dist/contracts/rental.contract.js.map +1 -0
- package/dist/contracts/revenuesplit.contract.d.ts +4 -0
- package/dist/contracts/revenuesplit.contract.js +211 -0
- package/dist/contracts/revenuesplit.contract.js.map +1 -0
- package/dist/contracts/rps.contract.js +17 -1
- package/dist/contracts/rps.contract.js.map +1 -1
- package/dist/contracts/savings.contract.d.ts +4 -0
- package/dist/contracts/savings.contract.js +208 -0
- package/dist/contracts/savings.contract.js.map +1 -0
- package/dist/contracts/subscription.contract.d.ts +4 -0
- package/dist/contracts/subscription.contract.js +241 -0
- package/dist/contracts/subscription.contract.js.map +1 -0
- package/dist/contracts/sweepstakes.contract.d.ts +4 -0
- package/dist/contracts/sweepstakes.contract.js +209 -0
- package/dist/contracts/sweepstakes.contract.js.map +1 -0
- package/dist/contracts/ticketing.contract.d.ts +4 -0
- package/dist/contracts/ticketing.contract.js +185 -0
- package/dist/contracts/ticketing.contract.js.map +1 -0
- package/dist/contracts/tipjar.contract.js +2 -0
- package/dist/contracts/tipjar.contract.js.map +1 -1
- package/dist/contracts/token.contract.js +135 -125
- package/dist/contracts/token.contract.js.map +1 -1
- package/dist/index.d.ts +39 -0
- package/dist/index.js +71 -1
- package/dist/index.js.map +1 -1
- package/dist/metadata.d.ts +7 -0
- package/dist/metadata.js +64 -1
- package/dist/metadata.js.map +1 -1
- package/dist/providers/block-provider.d.ts +22 -0
- package/dist/providers/block-provider.js +3 -0
- package/dist/providers/block-provider.js.map +1 -0
- package/dist/providers/haf-client.d.ts +30 -0
- package/dist/providers/haf-client.js +119 -0
- package/dist/providers/haf-client.js.map +1 -0
- package/dist/providers/haf-provider.d.ts +49 -0
- package/dist/providers/haf-provider.js +256 -0
- package/dist/providers/haf-provider.js.map +1 -0
- package/dist/providers/hive-provider.d.ts +13 -0
- package/dist/providers/hive-provider.js +25 -0
- package/dist/providers/hive-provider.js.map +1 -0
- package/dist/providers/index.d.ts +4 -0
- package/dist/providers/index.js +21 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/streamer.d.ts +21 -1
- package/dist/streamer.js +187 -62
- package/dist/streamer.js.map +1 -1
- package/dist/utils.js +11 -2
- package/dist/utils.js.map +1 -1
- package/package.json +16 -1
- package/.claude/settings.local.json +0 -12
- package/.env.example +0 -3
- package/.travis.yml +0 -11
- package/AGENTS.md +0 -35
- package/CLAUDE.md +0 -75
- package/ecosystem.config.js +0 -17
- package/examples/contracts/README.md +0 -8
- package/examples/contracts/exchange.ts +0 -38
- package/examples/contracts/poll.ts +0 -21
- package/examples/contracts/rps.ts +0 -19
- package/examples/contracts/tipjar.ts +0 -19
- package/jest.config.js +0 -9
- package/test-contract-block.md +0 -19
- package/tests/actions.spec.ts +0 -252
- package/tests/adapters/actions-persistence.spec.ts +0 -144
- package/tests/adapters/postgresql.adapter.spec.ts +0 -127
- package/tests/adapters/sqlite.adapter.spec.ts +0 -181
- package/tests/config-input.spec.ts +0 -90
- package/tests/contracts/coinflip.contract.spec.ts +0 -94
- package/tests/contracts/dice.contract.spec.ts +0 -87
- package/tests/contracts/entrants.json +0 -729
- package/tests/contracts/exchange.contract.spec.ts +0 -84
- package/tests/contracts/lotto.contract.spec.ts +0 -59
- package/tests/contracts/nft.contract.spec.ts +0 -948
- package/tests/contracts/token.contract.spec.ts +0 -90
- package/tests/exchanges/coingecko.exchange.spec.ts +0 -169
- package/tests/exchanges/exchange.base.spec.ts +0 -246
- package/tests/helpers/mock-adapter.ts +0 -214
- package/tests/helpers/mock-fetch.ts +0 -165
- package/tests/hive-chain-features.spec.ts +0 -319
- package/tests/hive-rates.spec.ts +0 -443
- package/tests/integration/hive-rates.integration.spec.ts +0 -35
- package/tests/metadata.spec.ts +0 -63
- package/tests/setup.ts +0 -30
- package/tests/streamer-actions.spec.ts +0 -274
- package/tests/streamer.spec.ts +0 -342
- package/tests/types/rates.spec.ts +0 -216
- package/tests/utils.spec.ts +0 -113
- package/tsconfig.build.json +0 -4
- package/tslint.json +0 -21
- package/wallaby.js +0 -26
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { SqliteAdapter } from "../../src/adapters/sqlite.adapter";
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
describe('SQLite Adapter', () => {
|
|
6
|
-
let sut: SqliteAdapter;
|
|
7
|
-
let testDbPath: string;
|
|
8
|
-
|
|
9
|
-
beforeEach(async () => {
|
|
10
|
-
testDbPath = path.resolve(__dirname, `../../src/adapters/hive-stream-test-basic-${Date.now()}-${Math.random()}.db`);
|
|
11
|
-
|
|
12
|
-
if (fs.existsSync(testDbPath)) {
|
|
13
|
-
fs.unlinkSync(testDbPath);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
sut = new SqliteAdapter(testDbPath);
|
|
17
|
-
await sut.create();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
afterEach(async () => {
|
|
21
|
-
if (sut && sut.getDb()) {
|
|
22
|
-
await sut.destroy();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (fs.existsSync(testDbPath)) {
|
|
26
|
-
fs.unlinkSync(testDbPath);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('find method returns values', async () => {
|
|
31
|
-
// Create a test table
|
|
32
|
-
await sut.db.schema.createTableIfNotExists('USERS', table => {
|
|
33
|
-
table.integer('id');
|
|
34
|
-
table.string('name');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// Insert test data
|
|
38
|
-
await sut.db('USERS').insert({ id: 1, name: 'John' });
|
|
39
|
-
|
|
40
|
-
const result = await sut.find('USERS', { id: 1, name: 'John' });
|
|
41
|
-
|
|
42
|
-
expect(result).toEqual([{ id: 1, name: 'John' }]);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test('findOne method returns value', async () => {
|
|
46
|
-
// Create a test table
|
|
47
|
-
await sut.db.schema.createTableIfNotExists('USERS', table => {
|
|
48
|
-
table.integer('id');
|
|
49
|
-
table.string('name');
|
|
50
|
-
table.string('email');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// Insert test data
|
|
54
|
-
await sut.db('USERS').insert({ id: 1, name: 'John', email: 'john@hotmail.com' });
|
|
55
|
-
|
|
56
|
-
const result = await sut.findOne('USERS', { id: 1, name: 'John', email: 'john@hotmail.com' });
|
|
57
|
-
|
|
58
|
-
expect(result).toEqual({ id: 1, name: 'John', email: 'john@hotmail.com' });
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('replace method replaces value', async () => {
|
|
62
|
-
// Create a test table
|
|
63
|
-
await sut.db.schema.createTableIfNotExists('USERS', table => {
|
|
64
|
-
table.integer('id').primary();
|
|
65
|
-
table.string('name');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Insert initial data
|
|
69
|
-
await sut.db('USERS').insert({ id: 1, name: 'John' });
|
|
70
|
-
|
|
71
|
-
const result = await sut.replace('USERS', { id: 1 }, { id: 1, name: 'Johnny' });
|
|
72
|
-
|
|
73
|
-
expect(result).toEqual({ id: 1, name: 'Johnny' });
|
|
74
|
-
|
|
75
|
-
// Verify the data was actually replaced
|
|
76
|
-
const updatedRecord = await sut.db('USERS').where({ id: 1 }).first();
|
|
77
|
-
expect(updatedRecord).toEqual({ id: 1, name: 'Johnny' });
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('insert method inserts values', async () => {
|
|
81
|
-
// Create a test table
|
|
82
|
-
await sut.db.schema.createTableIfNotExists('USERS', table => {
|
|
83
|
-
table.integer('id');
|
|
84
|
-
table.string('name');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
const result = await sut.insert('USERS', { id: 1, name: 'Alice' });
|
|
88
|
-
|
|
89
|
-
expect(result).toBe(true);
|
|
90
|
-
|
|
91
|
-
// Verify the data was actually inserted
|
|
92
|
-
const insertedRecord = await sut.db('USERS').where({ id: 1 }).first();
|
|
93
|
-
expect(insertedRecord).toEqual({ id: 1, name: 'Alice' });
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test('loadState and saveState work correctly', async () => {
|
|
97
|
-
const testData = {
|
|
98
|
-
lastBlockNumber: 12345,
|
|
99
|
-
actions: [{ id: 'test-action', type: 'test' }]
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
// Save state
|
|
103
|
-
const saveResult = await sut.saveState(testData);
|
|
104
|
-
expect(saveResult).toBe(true);
|
|
105
|
-
|
|
106
|
-
// Load state
|
|
107
|
-
const loadedState = await sut.loadState();
|
|
108
|
-
expect(loadedState?.lastBlockNumber).toBe(12345);
|
|
109
|
-
expect(loadedState?.actions).toEqual([{ id: 'test-action', type: 'test' }]);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test('processTransfer works correctly', async () => {
|
|
113
|
-
const mockPayload = {
|
|
114
|
-
contract: 'test-contract',
|
|
115
|
-
action: 'transfer',
|
|
116
|
-
payload: { amount: '100', recipient: 'bob' }
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
const mockMetadata = {
|
|
120
|
-
sender: 'alice',
|
|
121
|
-
amount: '100 HIVE'
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// Set up transaction context
|
|
125
|
-
await sut.processOperation({}, 12345, 'block123', 'prevblock', 'tx123', new Date());
|
|
126
|
-
|
|
127
|
-
const result = await sut.processTransfer({}, mockPayload, mockMetadata);
|
|
128
|
-
expect(result).toBe(true);
|
|
129
|
-
|
|
130
|
-
// Verify the transfer was stored
|
|
131
|
-
const transfers = await sut.getTransfers();
|
|
132
|
-
expect(transfers).toHaveLength(1);
|
|
133
|
-
expect(transfers[0].sender).toBe('alice');
|
|
134
|
-
expect(transfers[0].contractName).toBe('test-contract');
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
test('processCustomJson works correctly', async () => {
|
|
138
|
-
const mockPayload = {
|
|
139
|
-
contract: 'test-contract',
|
|
140
|
-
action: 'custom',
|
|
141
|
-
payload: { data: 'test' }
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const mockMetadata = {
|
|
145
|
-
sender: 'alice',
|
|
146
|
-
isSignedWithActiveKey: true
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
// Set up transaction context
|
|
150
|
-
await sut.processOperation({}, 12345, 'block123', 'prevblock', 'tx123', new Date());
|
|
151
|
-
|
|
152
|
-
const result = await sut.processCustomJson({}, mockPayload, mockMetadata);
|
|
153
|
-
expect(result).toBe(true);
|
|
154
|
-
|
|
155
|
-
// Verify the custom JSON was stored
|
|
156
|
-
const customJson = await sut.getJson();
|
|
157
|
-
expect(customJson).toHaveLength(1);
|
|
158
|
-
expect(customJson[0].sender).toBe('alice');
|
|
159
|
-
expect(customJson[0].contractName).toBe('test-contract');
|
|
160
|
-
expect(customJson[0].isSignedWithActiveKey).toBe(1);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
test('query method executes raw SQL', async () => {
|
|
164
|
-
// Create a test table
|
|
165
|
-
await sut.db.schema.createTableIfNotExists('USERS', table => {
|
|
166
|
-
table.integer('id');
|
|
167
|
-
table.string('name');
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// Insert test data
|
|
171
|
-
await sut.db('USERS').insert({ id: 1, name: 'Alice' });
|
|
172
|
-
await sut.db('USERS').insert({ id: 2, name: 'Bob' });
|
|
173
|
-
|
|
174
|
-
// Test raw SQL query
|
|
175
|
-
const result = await sut.query('SELECT * FROM USERS WHERE name = ?', ['Alice']);
|
|
176
|
-
|
|
177
|
-
expect(result).toHaveLength(1);
|
|
178
|
-
expect(result[0].name).toBe('Alice');
|
|
179
|
-
expect(result[0].id).toBe(1);
|
|
180
|
-
});
|
|
181
|
-
});
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { createConfig, normalizeConfigInput } from '../src/config';
|
|
2
|
-
import { Streamer } from '../src/streamer';
|
|
3
|
-
|
|
4
|
-
describe('Config input aliases', () => {
|
|
5
|
-
test('maps camelCase keys to canonical config keys', () => {
|
|
6
|
-
const normalized = normalizeConfigInput({
|
|
7
|
-
activeKey: 'active',
|
|
8
|
-
postingKey: 'posting',
|
|
9
|
-
username: 'alice',
|
|
10
|
-
jsonId: 'builder',
|
|
11
|
-
payloadIdentifier: 'payload',
|
|
12
|
-
blockCheckInterval: 1500,
|
|
13
|
-
blocksBehindWarning: 30,
|
|
14
|
-
resumeFromState: false,
|
|
15
|
-
catchUpBatchSize: 10,
|
|
16
|
-
catchUpDelayMs: 25,
|
|
17
|
-
apiNodes: ['https://api.hive.blog'],
|
|
18
|
-
debugMode: false
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
expect(normalized.ACTIVE_KEY).toBe('active');
|
|
22
|
-
expect(normalized.POSTING_KEY).toBe('posting');
|
|
23
|
-
expect(normalized.USERNAME).toBe('alice');
|
|
24
|
-
expect(normalized.JSON_ID).toBe('builder');
|
|
25
|
-
expect(normalized.PAYLOAD_IDENTIFIER).toBe('payload');
|
|
26
|
-
expect(normalized.BLOCK_CHECK_INTERVAL).toBe(1500);
|
|
27
|
-
expect(normalized.BLOCKS_BEHIND_WARNING).toBe(30);
|
|
28
|
-
expect(normalized.RESUME_FROM_STATE).toBe(false);
|
|
29
|
-
expect(normalized.CATCH_UP_BATCH_SIZE).toBe(10);
|
|
30
|
-
expect(normalized.CATCH_UP_DELAY_MS).toBe(25);
|
|
31
|
-
expect(normalized.API_NODES).toEqual(['https://api.hive.blog']);
|
|
32
|
-
expect(normalized.DEBUG_MODE).toBe(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('canonical keys override camelCase aliases when both are supplied', () => {
|
|
36
|
-
const normalized = normalizeConfigInput({
|
|
37
|
-
JSON_ID: 'canonical-id',
|
|
38
|
-
jsonId: 'alias-id'
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
expect(normalized.JSON_ID).toBe('canonical-id');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('createConfig merges aliases with defaults', () => {
|
|
45
|
-
const config = createConfig({
|
|
46
|
-
jsonId: 'custom-json-id',
|
|
47
|
-
debugMode: false
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
expect(config.JSON_ID).toBe('custom-json-id');
|
|
51
|
-
expect(config.DEBUG_MODE).toBe(false);
|
|
52
|
-
expect(Array.isArray(config.API_NODES)).toBe(true);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('Streamer constructor accepts camelCase config keys', async () => {
|
|
56
|
-
const sut = new Streamer({
|
|
57
|
-
username: 'builder-user',
|
|
58
|
-
postingKey: 'posting-key',
|
|
59
|
-
activeKey: 'active-key',
|
|
60
|
-
jsonId: 'custom-id'
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
expect(sut['config'].JSON_ID).toBe('custom-id');
|
|
64
|
-
expect(sut['username']).toBe('builder-user');
|
|
65
|
-
expect(sut['postingKey']).toBe('posting-key');
|
|
66
|
-
expect(sut['activeKey']).toBe('active-key');
|
|
67
|
-
|
|
68
|
-
await sut.stop();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test('Streamer.setConfig accepts camelCase config keys', async () => {
|
|
72
|
-
const sut = new Streamer();
|
|
73
|
-
|
|
74
|
-
sut.setConfig({
|
|
75
|
-
username: 'updated-user',
|
|
76
|
-
postingKey: 'updated-posting',
|
|
77
|
-
activeKey: 'updated-active',
|
|
78
|
-
blockCheckInterval: 333,
|
|
79
|
-
debugMode: false
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
expect(sut['config'].BLOCK_CHECK_INTERVAL).toBe(333);
|
|
83
|
-
expect(sut['config'].DEBUG_MODE).toBe(false);
|
|
84
|
-
expect(sut['username']).toBe('updated-user');
|
|
85
|
-
expect(sut['postingKey']).toBe('updated-posting');
|
|
86
|
-
expect(sut['activeKey']).toBe('updated-active');
|
|
87
|
-
|
|
88
|
-
await sut.stop();
|
|
89
|
-
});
|
|
90
|
-
});
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { createCoinflipContract } from '../../src/contracts/coinflip.contract';
|
|
2
|
-
import { sleep } from '@hiveio/dhive/lib/utils';
|
|
3
|
-
import { Streamer } from '../../src/streamer';
|
|
4
|
-
import { createMockAdapter } from '../helpers/mock-adapter';
|
|
5
|
-
|
|
6
|
-
jest.mock('uuid', () => ({
|
|
7
|
-
v4: jest.fn()
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
11
|
-
|
|
12
|
-
describe('Coinflip Contract', () => {
|
|
13
|
-
let sut: Streamer;
|
|
14
|
-
let contract: ReturnType<typeof createCoinflipContract>;
|
|
15
|
-
|
|
16
|
-
beforeEach(async () => {
|
|
17
|
-
sut = new Streamer();
|
|
18
|
-
await sut.registerAdapter(createMockAdapter());
|
|
19
|
-
contract = createCoinflipContract();
|
|
20
|
-
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
sut.api = jest.fn();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
afterEach(async () => {
|
|
26
|
-
await sut.stop();
|
|
27
|
-
jest.restoreAllMocks();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('Registers the contract', async () => {
|
|
31
|
-
await sut.registerContract(contract);
|
|
32
|
-
|
|
33
|
-
const findContract = sut['contracts'].find(c => c.name === 'coinflip');
|
|
34
|
-
expect(findContract).not.toBeUndefined();
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
test('User wins a flip', async () => {
|
|
38
|
-
await sut.registerContract(contract);
|
|
39
|
-
|
|
40
|
-
jest.spyOn(sut, 'getTransaction').mockResolvedValue({ test: 123 } as any);
|
|
41
|
-
jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
|
|
42
|
-
jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
|
|
43
|
-
jest.spyOn(sut['client'].database, 'getAccounts').mockResolvedValue([{ balance: '2000.000 HIVE' }] as any);
|
|
44
|
-
|
|
45
|
-
(uuidv4 as jest.Mock).mockReturnValue('j93jgsjghjdhgjfhgkfdhgkj34872394723');
|
|
46
|
-
|
|
47
|
-
const memo = JSON.stringify({
|
|
48
|
-
hive_stream: {
|
|
49
|
-
contract: 'coinflip',
|
|
50
|
-
action: 'flip',
|
|
51
|
-
payload: {
|
|
52
|
-
guess: 'heads',
|
|
53
|
-
seed: 'hj879879g7686876'
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
await sut.processOperation(['transfer', { from: 'testuser', amount: '9.000 HIVE', memo }], 778782, 'dfjfsdfsdfs4hfkj88787', 'fkjs7878dkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
|
|
59
|
-
|
|
60
|
-
await sleep(100);
|
|
61
|
-
|
|
62
|
-
expect(sut.getTransaction).toHaveBeenCalledWith(778782, 'fhkjsdhfkjsdf');
|
|
63
|
-
expect(sut.transferHiveTokens).toHaveBeenCalledWith('beggars', 'testuser', '18.000', 'HIVE', '[Winner] | Guess: heads | Server Roll: heads | Previous block id: fkjs7878dkfj | BlockID: dfjfsdfsdfs4hfkj88787 | Trx ID: fhkjsdhfkjsdf | Server Seed: j93jgsjghjdhgjfhgkfdhgkj34872394723');
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
test('User loses a flip', async () => {
|
|
67
|
-
await sut.registerContract(contract);
|
|
68
|
-
|
|
69
|
-
jest.spyOn(sut, 'getTransaction').mockResolvedValue({ test: 123 } as any);
|
|
70
|
-
jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
|
|
71
|
-
jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
|
|
72
|
-
jest.spyOn(sut['client'].database, 'getAccounts').mockResolvedValue([{ balance: '2000.000 HIVE' }] as any);
|
|
73
|
-
|
|
74
|
-
(uuidv4 as jest.Mock).mockReturnValue('j93jgsjghjdhgjfhgkfdhgkj34872394723');
|
|
75
|
-
|
|
76
|
-
const memo = JSON.stringify({
|
|
77
|
-
hive_stream: {
|
|
78
|
-
contract: 'coinflip',
|
|
79
|
-
action: 'flip',
|
|
80
|
-
payload: {
|
|
81
|
-
guess: 'heads',
|
|
82
|
-
seed: 'tulips'
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
await sut.processOperation(['transfer', { from: 'testuser', amount: '9.000 HIVE', memo }], 778782, 'dfjfsdfsdfs4hfkj88787', 'fkjs7878dkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
|
|
88
|
-
|
|
89
|
-
await sleep(100);
|
|
90
|
-
|
|
91
|
-
expect(sut.getTransaction).toHaveBeenCalledWith(778782, 'fhkjsdhfkjsdf');
|
|
92
|
-
expect(sut.transferHiveTokens).toHaveBeenCalledWith('beggars', 'testuser', '0.001', 'HIVE', '[Lost] | Guess: heads | Server Roll: tails | Previous block id: fkjs7878dkfj | BlockID: dfjfsdfsdfs4hfkj88787 | Trx ID: fhkjsdhfkjsdf | Server Seed: j93jgsjghjdhgjfhgkfdhgkj34872394723');
|
|
93
|
-
});
|
|
94
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { sleep } from '@hiveio/dhive/lib/utils';
|
|
2
|
-
import { createDiceContract } from './../../src/contracts/dice.contract';
|
|
3
|
-
import { Streamer } from '../../src/streamer';
|
|
4
|
-
import { createMockAdapter } from '../helpers/mock-adapter';
|
|
5
|
-
|
|
6
|
-
describe('Dice Contract', () => {
|
|
7
|
-
let sut: Streamer;
|
|
8
|
-
let contract: ReturnType<typeof createDiceContract>;
|
|
9
|
-
|
|
10
|
-
beforeEach(async () => {
|
|
11
|
-
sut = new Streamer();
|
|
12
|
-
await sut.registerAdapter(createMockAdapter());
|
|
13
|
-
|
|
14
|
-
contract = createDiceContract({ name: 'testdice' });
|
|
15
|
-
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
sut.api = jest.fn();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
afterEach(async () => {
|
|
21
|
-
await sut.stop();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
afterAll(() => {
|
|
25
|
-
jest.restoreAllMocks();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('Registers the dice contract', async () => {
|
|
29
|
-
await sut.registerContract(contract);
|
|
30
|
-
|
|
31
|
-
const findContract = sut['contracts'].find(c => c.name === 'testdice');
|
|
32
|
-
|
|
33
|
-
expect(findContract).not.toBeUndefined();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('User wins a roll', async () => {
|
|
37
|
-
await sut.registerContract(contract);
|
|
38
|
-
|
|
39
|
-
jest.spyOn(sut, 'getTransaction').mockResolvedValue({ test: 123 } as any);
|
|
40
|
-
jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
|
|
41
|
-
jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
|
|
42
|
-
jest.spyOn(sut['client'].database, 'getAccounts').mockResolvedValue([{ balance: '2000.000 HIVE' }] as any);
|
|
43
|
-
|
|
44
|
-
const memo = JSON.stringify({
|
|
45
|
-
hive_stream: {
|
|
46
|
-
contract: 'testdice',
|
|
47
|
-
action: 'roll',
|
|
48
|
-
payload: {
|
|
49
|
-
roll: 69
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
await sut.processOperation(['transfer', { from: 'testuser', amount: '9.000 HIVE', memo }], 778782, 'dfjfsdfsdfsd34hfkj88787', 'fkjsdkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
|
|
55
|
-
|
|
56
|
-
await sleep(100);
|
|
57
|
-
|
|
58
|
-
expect(sut.getTransaction).toHaveBeenCalledWith(778782, 'fhkjsdhfkjsdf');
|
|
59
|
-
expect(sut.transferHiveTokens).toHaveBeenCalledWith('beggars', 'testuser', '12.391', 'HIVE', 'You won 12.391 HIVE. Roll: 54, Your guess: 69');
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('User loses a roll', async () => {
|
|
63
|
-
await sut.registerContract(contract);
|
|
64
|
-
|
|
65
|
-
jest.spyOn(sut, 'getTransaction').mockResolvedValue({ test: 123 } as any);
|
|
66
|
-
jest.spyOn(sut, 'verifyTransfer').mockResolvedValue(true as any);
|
|
67
|
-
jest.spyOn(sut, 'transferHiveTokens').mockResolvedValue(true as any);
|
|
68
|
-
jest.spyOn(sut['client'].database, 'getAccounts').mockResolvedValue([{ balance: '2000.000 HIVE' }] as any);
|
|
69
|
-
|
|
70
|
-
const memo = JSON.stringify({
|
|
71
|
-
hive_stream: {
|
|
72
|
-
contract: 'testdice',
|
|
73
|
-
action: 'roll',
|
|
74
|
-
payload: {
|
|
75
|
-
roll: 10
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
await sut.processOperation(['transfer', { from: 'testuser', amount: '9.000 HIVE', memo }], 778782, 'dfjfsdfsdfsd34hfkj88787', 'fkjsdkfj', 'fhkjsdhfkjsdf', '2019-06-23' as any);
|
|
81
|
-
|
|
82
|
-
await sleep(100);
|
|
83
|
-
|
|
84
|
-
expect(sut.getTransaction).toHaveBeenCalledWith(778782, 'fhkjsdhfkjsdf');
|
|
85
|
-
expect(sut.transferHiveTokens).toHaveBeenCalledWith('beggars', 'testuser', '0.001', 'HIVE', 'You lost 9.000 HIVE. Roll: 54, Your guess: 10');
|
|
86
|
-
});
|
|
87
|
-
});
|