@cardano-sdk/golden-test-generator 0.1.4 → 0.1.8
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/applyValue.d.ts +3 -0
- package/dist/AddressBalance/applyValue.d.ts.map +1 -0
- package/dist/AddressBalance/applyValue.js +30 -0
- package/dist/AddressBalance/applyValue.js.map +1 -0
- package/dist/AddressBalance/getOnChainAddressBalances.d.ts +17 -0
- package/dist/AddressBalance/getOnChainAddressBalances.d.ts.map +1 -0
- package/dist/AddressBalance/getOnChainAddressBalances.js +98 -0
- package/dist/AddressBalance/getOnChainAddressBalances.js.map +1 -0
- package/{src/AddressBalance/index.ts → dist/AddressBalance/index.d.ts} +1 -0
- package/dist/AddressBalance/index.d.ts.map +1 -0
- package/dist/AddressBalance/index.js +15 -0
- package/dist/AddressBalance/index.js.map +1 -0
- package/dist/Block/getBlocks.d.ts +14 -0
- package/dist/Block/getBlocks.d.ts.map +1 -0
- package/dist/Block/getBlocks.js +76 -0
- package/dist/Block/getBlocks.js.map +1 -0
- package/dist/Block/index.d.ts +2 -0
- package/dist/Block/index.d.ts.map +1 -0
- package/dist/Block/index.js +14 -0
- package/dist/Block/index.js.map +1 -0
- package/dist/Content.d.ts +23 -0
- package/dist/Content.d.ts.map +1 -0
- package/dist/Content.js +24 -0
- package/dist/Content.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +114 -0
- package/dist/index.js.map +1 -0
- package/dist/util.d.ts +9 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +14 -0
- package/dist/util.js.map +1 -0
- package/package.json +11 -2
- 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/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/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
|
-
});
|