@cardano-sdk/golden-test-generator 0.1.3 → 0.1.7
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/LICENSE +201 -0
- package/NOTICE +5 -0
- package/dist/AddressBalance/getOnChainAddressBalances.js +3 -3
- package/dist/AddressBalance/getOnChainAddressBalances.js.map +1 -1
- package/dist/Block/getBlocks.js +2 -2
- package/dist/Block/getBlocks.js.map +1 -1
- package/dist/Content.d.ts.map +1 -1
- package/dist/Content.js +5 -5
- package/dist/Content.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +10 -2
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/jest.config.js +0 -1
- package/src/.eslintrc.js +0 -7
- package/src/AddressBalance/applyValue.ts +0 -31
- package/src/AddressBalance/getOnChainAddressBalances.ts +0 -137
- package/src/AddressBalance/index.ts +0 -2
- package/src/Block/getBlocks.ts +0 -101
- package/src/Block/index.ts +0 -1
- package/src/Content.ts +0 -43
- package/src/index.ts +0 -127
- package/src/tsconfig.json +0 -10
- package/src/util.ts +0 -15
- package/test/.eslintrc.js +0 -7
- package/test/AddressBalance.test.ts +0 -184
- package/test/tsconfig.json +0 -10
package/src/Content.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { ChainSync, Schema as Cardano } from '@cardano-ogmios/client';
|
|
2
|
-
import { Commit } from 'git-last-commit';
|
|
3
|
-
import { getLastCommitPromise } from './util';
|
|
4
|
-
const packageJson = require('../package.json');
|
|
5
|
-
|
|
6
|
-
export type Metadata = {
|
|
7
|
-
cardano: {
|
|
8
|
-
compactGenesis: Cardano.CompactGenesis;
|
|
9
|
-
intersection: ChainSync.Intersection;
|
|
10
|
-
};
|
|
11
|
-
software: {
|
|
12
|
-
name: string;
|
|
13
|
-
version: string;
|
|
14
|
-
commit: Pick<Commit, 'hash' | 'tags'>;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type GeneratorMetadata = { metadata: { cardano: Metadata['cardano'] } };
|
|
19
|
-
|
|
20
|
-
export const prepareContent = async <Body>(
|
|
21
|
-
metadata: Omit<Metadata, 'software'>,
|
|
22
|
-
body: Body
|
|
23
|
-
): Promise<{
|
|
24
|
-
metadata: Metadata;
|
|
25
|
-
body: Body;
|
|
26
|
-
}> => {
|
|
27
|
-
const lastCommit = await getLastCommitPromise();
|
|
28
|
-
return {
|
|
29
|
-
metadata: {
|
|
30
|
-
...metadata,
|
|
31
|
-
|
|
32
|
-
software: {
|
|
33
|
-
name: packageJson.name,
|
|
34
|
-
version: packageJson.version,
|
|
35
|
-
commit: {
|
|
36
|
-
hash: lastCommit.hash,
|
|
37
|
-
tags: lastCommit.tags
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
body
|
|
42
|
-
};
|
|
43
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import chalk from 'chalk';
|
|
4
|
-
import { Command } from 'commander';
|
|
5
|
-
import hash from 'object-hash';
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
import { SingleBar, Options } from 'cli-progress';
|
|
8
|
-
import { ensureDir, writeFile } from 'fs-extra';
|
|
9
|
-
import JSONBig from 'json-bigint';
|
|
10
|
-
import { AddressBalancesResponse, getOnChainAddressBalances } from './AddressBalance';
|
|
11
|
-
import { getBlocks, GetBlocksResponse } from './Block';
|
|
12
|
-
import { prepareContent } from './Content';
|
|
13
|
-
|
|
14
|
-
const clear = require('clear');
|
|
15
|
-
const packageJson = require('../package.json');
|
|
16
|
-
|
|
17
|
-
clear();
|
|
18
|
-
console.log(chalk.blue('Cardano Golden Test Generator'));
|
|
19
|
-
|
|
20
|
-
const createProgressBar = (lastblockHeight: number) =>
|
|
21
|
-
new SingleBar({
|
|
22
|
-
format: `Syncing from genesis to block ${lastblockHeight} | ${chalk.blue(
|
|
23
|
-
'{bar}'
|
|
24
|
-
)} | {percentage}% || {value}/{total} Blocks`,
|
|
25
|
-
barCompleteChar: '\u2588',
|
|
26
|
-
barIncompleteChar: '\u2591',
|
|
27
|
-
hideCursor: true,
|
|
28
|
-
renderThrottle: 300
|
|
29
|
-
} as Options);
|
|
30
|
-
|
|
31
|
-
const program = new Command('cardano-golden-test-generator');
|
|
32
|
-
|
|
33
|
-
program
|
|
34
|
-
.option('--ogmios-host [ogmiosHost]', 'Ogmios host. Defaults to localhost')
|
|
35
|
-
.option('--ogmios-port [ogmiosPort]', 'Ogmios TCP port. Defaults to 1337', (port) => Number.parseInt(port))
|
|
36
|
-
.option('--ogmios-tls [ogmiosTls]', 'Is Ogmios being served over a secure connection?. Defaults to false', (port) =>
|
|
37
|
-
Number.parseInt(port)
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
program
|
|
41
|
-
.command('address-balance')
|
|
42
|
-
.description('Balance of addresses, determined by syncing the chain from genesis')
|
|
43
|
-
.argument('[addresses]', 'Comma-separated list of addresses', (addresses) =>
|
|
44
|
-
addresses.split(',').filter((a) => a !== '')
|
|
45
|
-
)
|
|
46
|
-
.requiredOption('--at-blocks [atBlocks]', 'Balance of the addresses at block heights', (heights) =>
|
|
47
|
-
heights
|
|
48
|
-
.split(',')
|
|
49
|
-
.filter((b) => b !== '')
|
|
50
|
-
.map((height) => Number.parseInt(height))
|
|
51
|
-
)
|
|
52
|
-
.requiredOption('--out-dir [outDir]', 'File path to write results to')
|
|
53
|
-
.action(async (addresses: string[], { atBlocks, outDir }) => {
|
|
54
|
-
try {
|
|
55
|
-
const { ogmiosHost, ogmiosPort, ogmiosTls } = program.opts();
|
|
56
|
-
const atBlockHeights = atBlocks.sort((a: number, b: number) => a - b);
|
|
57
|
-
const lastBlockHeight = atBlockHeights[atBlockHeights.length - 1];
|
|
58
|
-
const progress = createProgressBar(lastBlockHeight);
|
|
59
|
-
await ensureDir(outDir);
|
|
60
|
-
progress.start(lastBlockHeight, 0);
|
|
61
|
-
const { balances, metadata } = await getOnChainAddressBalances(addresses, atBlockHeights, {
|
|
62
|
-
ogmiosConnectionConfig: { host: ogmiosHost, port: ogmiosPort, tls: ogmiosTls },
|
|
63
|
-
onBlock: (blockHeight) => {
|
|
64
|
-
progress.update(blockHeight);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
const content = await prepareContent<AddressBalancesResponse['balances']>(metadata, balances);
|
|
68
|
-
progress.stop();
|
|
69
|
-
const fileName = path.join(outDir, `address-balances-${hash(content)}.json`);
|
|
70
|
-
|
|
71
|
-
console.log(`Writing ${fileName}`);
|
|
72
|
-
await writeFile(fileName, JSONBig.stringify(content, undefined, 2));
|
|
73
|
-
process.exit(0);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
console.error(error);
|
|
76
|
-
process.exit(1);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
program
|
|
81
|
-
.command('get-block')
|
|
82
|
-
.description('Dump the requested blocks in their raw structure')
|
|
83
|
-
.argument('[blockHeights]', 'Comma-separated list of blocks by number', (blockHeights) =>
|
|
84
|
-
blockHeights
|
|
85
|
-
.split(',')
|
|
86
|
-
.filter((b) => b !== '')
|
|
87
|
-
.map((blockHeight) => Number.parseInt(blockHeight))
|
|
88
|
-
)
|
|
89
|
-
.requiredOption('--out-dir [outDir]', 'File path to write results to')
|
|
90
|
-
.action(async (blockHeights: number[], { outDir }) => {
|
|
91
|
-
try {
|
|
92
|
-
const { ogmiosHost, ogmiosPort, ogmiosTls } = program.opts();
|
|
93
|
-
const sortedblockHeights = blockHeights.sort((a: number, b: number) => a - b);
|
|
94
|
-
const lastblockHeight = sortedblockHeights[sortedblockHeights.length - 1];
|
|
95
|
-
const progress = createProgressBar(lastblockHeight);
|
|
96
|
-
await ensureDir(outDir);
|
|
97
|
-
progress.start(lastblockHeight, 0);
|
|
98
|
-
const { blocks, metadata } = await getBlocks(sortedblockHeights, {
|
|
99
|
-
logger: console,
|
|
100
|
-
ogmiosConnectionConfig: { host: ogmiosHost, port: ogmiosPort, tls: ogmiosTls },
|
|
101
|
-
onBlock: (blockHeight) => {
|
|
102
|
-
progress.update(blockHeight);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
progress.stop();
|
|
106
|
-
const content = await prepareContent<GetBlocksResponse['blocks']>(metadata, blocks);
|
|
107
|
-
const fileName = path.join(outDir, `blocks-${hash(content)}.json`);
|
|
108
|
-
|
|
109
|
-
console.log(`Writing ${fileName}`);
|
|
110
|
-
await writeFile(fileName, JSONBig.stringify(content, undefined, 2));
|
|
111
|
-
process.exit(0);
|
|
112
|
-
} catch (error) {
|
|
113
|
-
console.error(error);
|
|
114
|
-
process.exit(1);
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
program.version(packageJson.version);
|
|
119
|
-
if (process.argv.slice(2).length === 0) {
|
|
120
|
-
program.outputHelp();
|
|
121
|
-
process.exit(1);
|
|
122
|
-
} else {
|
|
123
|
-
program.parseAsync(process.argv).catch((error) => {
|
|
124
|
-
console.error(error);
|
|
125
|
-
process.exit(0);
|
|
126
|
-
});
|
|
127
|
-
}
|
package/src/tsconfig.json
DELETED
package/src/util.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Schema } from '@cardano-ogmios/client';
|
|
2
|
-
import { getLastCommit } from 'git-last-commit';
|
|
3
|
-
// eslint-disable-next-line unicorn/prefer-node-protocol
|
|
4
|
-
import { promisify } from 'util';
|
|
5
|
-
|
|
6
|
-
// Todo: Hoist to @cardano-ogmios/client
|
|
7
|
-
export const isByronStandardBlock = (block: Schema.Block): block is { byron: Schema.StandardBlock } =>
|
|
8
|
-
(block as { byron: Schema.StandardBlock }).byron?.header.slot !== undefined;
|
|
9
|
-
|
|
10
|
-
export const isByronEpochBoundaryBlock = (block: Schema.Block): block is { byron: Schema.EpochBoundaryBlock } => {
|
|
11
|
-
const castBlock = block as { byron: Schema.EpochBoundaryBlock };
|
|
12
|
-
return castBlock.byron?.hash !== undefined && castBlock.byron?.header.epoch !== undefined;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const getLastCommitPromise = promisify(getLastCommit);
|
package/test/.eslintrc.js
DELETED
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
import { AddressBalances, applyValue } from '../src/AddressBalance';
|
|
2
|
-
|
|
3
|
-
describe('AddressBalance', () => {
|
|
4
|
-
describe('applyValueToBalance', () => {
|
|
5
|
-
let balances: AddressBalances;
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
balances = {
|
|
8
|
-
ab: {
|
|
9
|
-
coins: 100
|
|
10
|
-
},
|
|
11
|
-
cd: {
|
|
12
|
-
assets: {
|
|
13
|
-
12: 10n
|
|
14
|
-
},
|
|
15
|
-
coins: 400
|
|
16
|
-
},
|
|
17
|
-
ef: {
|
|
18
|
-
assets: {
|
|
19
|
-
12: 10n,
|
|
20
|
-
34: 20n
|
|
21
|
-
},
|
|
22
|
-
coins: 500
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
});
|
|
26
|
-
describe('values containing only coins', () => {
|
|
27
|
-
const address = 'ab';
|
|
28
|
-
it('adds the coins balance', () => {
|
|
29
|
-
expect(applyValue(balances[address], { coins: 50 })).toEqual({ coins: 150 });
|
|
30
|
-
});
|
|
31
|
-
it('subtracts the coins balance when spending', () => {
|
|
32
|
-
expect(applyValue(balances[address], { coins: 50 }, true)).toEqual({ coins: 50 });
|
|
33
|
-
});
|
|
34
|
-
it('returns the same balance if coins is 0', () => {
|
|
35
|
-
expect(applyValue(balances[address], { coins: 0 })).toEqual({ coins: 100 });
|
|
36
|
-
});
|
|
37
|
-
it('returns the same balance if coins is 0 when spending', () => {
|
|
38
|
-
expect(applyValue(balances[address], { coins: 0 }, true)).toEqual({ coins: 100 });
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
describe('values containing an asset', () => {
|
|
42
|
-
const address = 'cd';
|
|
43
|
-
it('adds the coins and asset balance', () => {
|
|
44
|
-
expect(
|
|
45
|
-
applyValue(balances[address], {
|
|
46
|
-
assets: {
|
|
47
|
-
12: 10n
|
|
48
|
-
},
|
|
49
|
-
coins: 50
|
|
50
|
-
})
|
|
51
|
-
).toEqual({ assets: { 12: 20n }, coins: 450 });
|
|
52
|
-
});
|
|
53
|
-
it('subtracts the coins and asset balance when spending', () => {
|
|
54
|
-
expect(applyValue(balances[address], { assets: { 12: 9n }, coins: 50 }, true)).toEqual({
|
|
55
|
-
assets: { 12: 1n },
|
|
56
|
-
coins: 350
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
it('returns the same balance if coins and asset is 0', () => {
|
|
60
|
-
expect(applyValue(balances[address], { assets: { 12: 0n }, coins: 0 })).toEqual({
|
|
61
|
-
assets: { 12: 10n },
|
|
62
|
-
coins: 400
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
it('returns the same balance if coins and asset is 0 when spending', () => {
|
|
66
|
-
expect(applyValue(balances[address], { assets: { 12: 0n }, coins: 0 }, true)).toEqual({
|
|
67
|
-
assets: { 12: 10n },
|
|
68
|
-
coins: 400
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
describe('values containing multiple assets', () => {
|
|
73
|
-
const address = 'ef';
|
|
74
|
-
it('adds the coins and assets balance', () => {
|
|
75
|
-
expect(
|
|
76
|
-
applyValue(balances[address], {
|
|
77
|
-
assets: {
|
|
78
|
-
12: 10n,
|
|
79
|
-
34: 55n
|
|
80
|
-
},
|
|
81
|
-
coins: 50
|
|
82
|
-
})
|
|
83
|
-
).toEqual({
|
|
84
|
-
assets: {
|
|
85
|
-
12: 20n,
|
|
86
|
-
34: 75n
|
|
87
|
-
},
|
|
88
|
-
coins: 550
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
it('subtracts the coins and asset balances when spending', () => {
|
|
92
|
-
expect(
|
|
93
|
-
applyValue(
|
|
94
|
-
balances[address],
|
|
95
|
-
{
|
|
96
|
-
assets: {
|
|
97
|
-
12: 9n,
|
|
98
|
-
34: 15n
|
|
99
|
-
},
|
|
100
|
-
coins: 50
|
|
101
|
-
},
|
|
102
|
-
true
|
|
103
|
-
)
|
|
104
|
-
).toEqual({
|
|
105
|
-
assets: {
|
|
106
|
-
12: 1n,
|
|
107
|
-
34: 5n
|
|
108
|
-
},
|
|
109
|
-
coins: 450
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
it('adds new assets to the address balance', () => {
|
|
113
|
-
expect(
|
|
114
|
-
applyValue(balances[address], {
|
|
115
|
-
assets: {
|
|
116
|
-
new: 100n
|
|
117
|
-
},
|
|
118
|
-
coins: 1
|
|
119
|
-
})
|
|
120
|
-
).toEqual({
|
|
121
|
-
assets: {
|
|
122
|
-
12: 10n,
|
|
123
|
-
34: 20n,
|
|
124
|
-
new: 100n
|
|
125
|
-
},
|
|
126
|
-
coins: 501
|
|
127
|
-
});
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
describe('balance containing multiple assets, value containing only coins', () => {
|
|
131
|
-
const address = 'ef';
|
|
132
|
-
it('adds the coins', () => {
|
|
133
|
-
expect(
|
|
134
|
-
applyValue(balances[address], {
|
|
135
|
-
coins: 50
|
|
136
|
-
})
|
|
137
|
-
).toEqual({
|
|
138
|
-
assets: {
|
|
139
|
-
12: 10n,
|
|
140
|
-
34: 20n
|
|
141
|
-
},
|
|
142
|
-
coins: 550
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
it('subtracts the coins', () => {
|
|
146
|
-
expect(applyValue(balances[address], { coins: 50 }, true)).toEqual({
|
|
147
|
-
assets: {
|
|
148
|
-
12: 10n,
|
|
149
|
-
34: 20n
|
|
150
|
-
},
|
|
151
|
-
coins: 450
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
describe('guarding against negative balances', () => {
|
|
156
|
-
const address = 'cd';
|
|
157
|
-
it('throws if the balance calculated for coins is less than 0', () => {
|
|
158
|
-
expect(() =>
|
|
159
|
-
applyValue(
|
|
160
|
-
balances[address],
|
|
161
|
-
{
|
|
162
|
-
coins: 500
|
|
163
|
-
},
|
|
164
|
-
true
|
|
165
|
-
)
|
|
166
|
-
).toThrow();
|
|
167
|
-
});
|
|
168
|
-
it('throws if the balance calculated for assets is less than 0', () => {
|
|
169
|
-
expect(() =>
|
|
170
|
-
applyValue(
|
|
171
|
-
balances[address],
|
|
172
|
-
{
|
|
173
|
-
assets: {
|
|
174
|
-
12: 20n
|
|
175
|
-
},
|
|
176
|
-
coins: 1
|
|
177
|
-
},
|
|
178
|
-
true
|
|
179
|
-
)
|
|
180
|
-
).toThrow();
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
});
|
|
184
|
-
});
|