@human-protocol/sdk 1.0.4 → 1.0.5
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/dist/src/constants.d.ts.map +1 -0
- package/dist/src/decorators.d.ts.map +1 -0
- package/dist/src/enums.d.ts.map +1 -0
- package/dist/src/error.d.ts.map +1 -0
- package/dist/{escrow.d.ts → src/escrow.d.ts} +8 -0
- package/dist/src/escrow.d.ts.map +1 -0
- package/dist/{escrow.js → src/escrow.js} +23 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/init.d.ts.map +1 -0
- package/dist/src/interfaces.d.ts.map +1 -0
- package/dist/src/kvstore.d.ts.map +1 -0
- package/dist/src/queries.d.ts.map +1 -0
- package/dist/src/staking.d.ts.map +1 -0
- package/dist/src/storage.d.ts.map +1 -0
- package/dist/{storage.js → src/storage.js} +1 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/test/escrow.test.d.ts +2 -0
- package/dist/test/escrow.test.d.ts.map +1 -0
- package/dist/test/escrow.test.js +827 -0
- package/dist/test/init.test.d.ts +2 -0
- package/dist/test/init.test.d.ts.map +1 -0
- package/dist/test/init.test.js +70 -0
- package/dist/test/kvstore.test.d.ts +2 -0
- package/dist/test/kvstore.test.d.ts.map +1 -0
- package/dist/test/kvstore.test.js +125 -0
- package/dist/test/staking.test.d.ts +2 -0
- package/dist/test/staking.test.d.ts.map +1 -0
- package/dist/test/staking.test.js +375 -0
- package/dist/test/storage.test.d.ts +2 -0
- package/dist/test/storage.test.d.ts.map +1 -0
- package/dist/test/storage.test.js +287 -0
- package/dist/test/utils/constants.d.ts +45 -0
- package/dist/test/utils/constants.d.ts.map +1 -0
- package/dist/test/utils/constants.js +47 -0
- package/package.json +3 -5
- package/src/escrow.ts +29 -2
- package/src/staking.ts +1 -0
- package/src/storage.ts +1 -0
- package/dist/constants.d.ts.map +0 -1
- package/dist/decorators.d.ts.map +0 -1
- package/dist/enums.d.ts.map +0 -1
- package/dist/error.d.ts.map +0 -1
- package/dist/escrow.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/init.d.ts.map +0 -1
- package/dist/interfaces.d.ts.map +0 -1
- package/dist/kvstore.d.ts.map +0 -1
- package/dist/queries.d.ts.map +0 -1
- package/dist/staking.d.ts.map +0 -1
- package/dist/storage.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/test/escrow.test.ts +0 -1339
- package/test/init.test.ts +0 -88
- package/test/kvstore.test.ts +0 -208
- package/test/staking.test.ts +0 -640
- package/test/storage.test.ts +0 -422
- package/test/utils/constants.ts +0 -67
- /package/dist/{constants.d.ts → src/constants.d.ts} +0 -0
- /package/dist/{constants.js → src/constants.js} +0 -0
- /package/dist/{decorators.d.ts → src/decorators.d.ts} +0 -0
- /package/dist/{decorators.js → src/decorators.js} +0 -0
- /package/dist/{enums.d.ts → src/enums.d.ts} +0 -0
- /package/dist/{enums.js → src/enums.js} +0 -0
- /package/dist/{error.d.ts → src/error.d.ts} +0 -0
- /package/dist/{error.js → src/error.js} +0 -0
- /package/dist/{index.d.ts → src/index.d.ts} +0 -0
- /package/dist/{index.js → src/index.js} +0 -0
- /package/dist/{init.d.ts → src/init.d.ts} +0 -0
- /package/dist/{init.js → src/init.js} +0 -0
- /package/dist/{interfaces.d.ts → src/interfaces.d.ts} +0 -0
- /package/dist/{interfaces.js → src/interfaces.js} +0 -0
- /package/dist/{kvstore.d.ts → src/kvstore.d.ts} +0 -0
- /package/dist/{kvstore.js → src/kvstore.js} +0 -0
- /package/dist/{queries.d.ts → src/queries.d.ts} +0 -0
- /package/dist/{queries.js → src/queries.js} +0 -0
- /package/dist/{staking.d.ts → src/staking.d.ts} +0 -0
- /package/dist/{staking.js → src/staking.js} +0 -0
- /package/dist/{storage.d.ts → src/storage.d.ts} +0 -0
- /package/dist/{types.d.ts → src/types.d.ts} +0 -0
- /package/dist/{types.js → src/types.js} +0 -0
- /package/dist/{utils.d.ts → src/utils.d.ts} +0 -0
- /package/dist/{utils.js → src/utils.js} +0 -0
|
@@ -0,0 +1,827 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
+
const vitest_1 = require("vitest");
|
|
8
|
+
const ethers_1 = require("ethers");
|
|
9
|
+
const escrow_1 = __importDefault(require("../src/escrow"));
|
|
10
|
+
const constants_1 = require("./utils/constants");
|
|
11
|
+
const error_1 = require("../src/error");
|
|
12
|
+
const init_1 = __importDefault(require("../src/init"));
|
|
13
|
+
const typechain_types_1 = require("@human-protocol/core/typechain-types");
|
|
14
|
+
const constants_2 = require("../src/constants");
|
|
15
|
+
const types_1 = require("../src/types");
|
|
16
|
+
vitest_1.vi.mock('../src/init');
|
|
17
|
+
(0, vitest_1.describe)('EscrowClient', () => {
|
|
18
|
+
const provider = new ethers_1.ethers.providers.JsonRpcProvider();
|
|
19
|
+
let escrowClient, mockSigner, mockEscrowContract, mockEscrowFactoryContract, mockTokenContract;
|
|
20
|
+
(0, vitest_1.beforeEach)(async () => {
|
|
21
|
+
mockSigner = {
|
|
22
|
+
...provider.getSigner(),
|
|
23
|
+
getAddress: vitest_1.vi.fn().mockReturnValue(ethers_1.ethers.constants.AddressZero),
|
|
24
|
+
};
|
|
25
|
+
mockEscrowContract = {
|
|
26
|
+
createEscrow: vitest_1.vi.fn(),
|
|
27
|
+
setup: vitest_1.vi.fn(),
|
|
28
|
+
createAndSetupEscrow: vitest_1.vi.fn(),
|
|
29
|
+
fund: vitest_1.vi.fn(),
|
|
30
|
+
storeResults: vitest_1.vi.fn(),
|
|
31
|
+
complete: vitest_1.vi.fn(),
|
|
32
|
+
bulkPayOut: vitest_1.vi.fn(),
|
|
33
|
+
cancel: vitest_1.vi.fn(),
|
|
34
|
+
abort: vitest_1.vi.fn(),
|
|
35
|
+
addTrustedHandlers: vitest_1.vi.fn(),
|
|
36
|
+
getBalance: vitest_1.vi.fn(),
|
|
37
|
+
manifestUrl: vitest_1.vi.fn(),
|
|
38
|
+
finalResultsUrl: vitest_1.vi.fn(),
|
|
39
|
+
token: vitest_1.vi.fn(),
|
|
40
|
+
status: vitest_1.vi.fn(),
|
|
41
|
+
getLaunchedEscrows: vitest_1.vi.fn(),
|
|
42
|
+
getEscrowsFiltered: vitest_1.vi.fn(),
|
|
43
|
+
address: ethers_1.ethers.constants.AddressZero,
|
|
44
|
+
recordingOracle: vitest_1.vi.fn(),
|
|
45
|
+
reputationOracle: vitest_1.vi.fn(),
|
|
46
|
+
};
|
|
47
|
+
mockEscrowFactoryContract = {
|
|
48
|
+
createEscrow: vitest_1.vi.fn(),
|
|
49
|
+
hasEscrow: vitest_1.vi.fn(),
|
|
50
|
+
lastEscrow: vitest_1.vi.fn(),
|
|
51
|
+
};
|
|
52
|
+
mockTokenContract = {
|
|
53
|
+
allowance: vitest_1.vi.fn(),
|
|
54
|
+
approve: vitest_1.vi.fn(),
|
|
55
|
+
transfer: vitest_1.vi.fn(),
|
|
56
|
+
};
|
|
57
|
+
const getClientParamsMock = init_1.default.getParams;
|
|
58
|
+
getClientParamsMock.mockResolvedValue({
|
|
59
|
+
signerOrProvider: mockSigner,
|
|
60
|
+
network: constants_1.FAKE_NETWORK,
|
|
61
|
+
});
|
|
62
|
+
// Mock EscrowFactory__factory.connect to return the mock EscrowFactory
|
|
63
|
+
vitest_1.vi.spyOn(typechain_types_1.EscrowFactory__factory, 'connect').mockReturnValue(mockEscrowFactoryContract);
|
|
64
|
+
// Mock Escrow__factory.connect to return the mock Escrow
|
|
65
|
+
vitest_1.vi.spyOn(typechain_types_1.Escrow__factory, 'connect').mockReturnValue(mockEscrowContract);
|
|
66
|
+
// Mock HMToken__factory.connect to return the mock HMToken
|
|
67
|
+
vitest_1.vi.spyOn(typechain_types_1.HMToken__factory, 'connect').mockReturnValue(mockTokenContract);
|
|
68
|
+
escrowClient = new escrow_1.default(await init_1.default.getParams(mockSigner));
|
|
69
|
+
escrowClient.escrowContract = mockEscrowContract;
|
|
70
|
+
escrowClient.tokenContract = mockTokenContract;
|
|
71
|
+
escrowClient.escrowFactoryContract = mockEscrowFactoryContract;
|
|
72
|
+
});
|
|
73
|
+
(0, vitest_1.afterEach)(() => {
|
|
74
|
+
vitest_1.vi.restoreAllMocks();
|
|
75
|
+
});
|
|
76
|
+
(0, vitest_1.describe)('createEscrow', () => {
|
|
77
|
+
(0, vitest_1.test)('should throw an error if tokenAddress is an invalid address', async () => {
|
|
78
|
+
const invalidAddress = constants_1.FAKE_ADDRESS;
|
|
79
|
+
await (0, vitest_1.expect)(escrowClient.createEscrow(invalidAddress, [
|
|
80
|
+
ethers_1.ethers.constants.AddressZero,
|
|
81
|
+
])).rejects.toThrow(error_1.ErrorInvalidTokenAddress);
|
|
82
|
+
});
|
|
83
|
+
(0, vitest_1.test)('should throw an error if trustedHandlers contains an invalid address', async () => {
|
|
84
|
+
await (0, vitest_1.expect)(escrowClient.createEscrow(ethers_1.ethers.constants.AddressZero, [constants_1.FAKE_ADDRESS])).rejects.toThrow(new error_1.InvalidEthereumAddressError(constants_1.FAKE_ADDRESS));
|
|
85
|
+
});
|
|
86
|
+
(0, vitest_1.test)('should create an escrow and return its address', async () => {
|
|
87
|
+
const tokenAddress = ethers_1.ethers.constants.AddressZero;
|
|
88
|
+
const trustedHandlers = [ethers_1.ethers.constants.AddressZero];
|
|
89
|
+
const expectedEscrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
90
|
+
// Create a spy object for the createEscrow method
|
|
91
|
+
const createEscrowSpy = vitest_1.vi
|
|
92
|
+
.spyOn(escrowClient.escrowFactoryContract, 'createEscrow')
|
|
93
|
+
.mockImplementation(() => ({
|
|
94
|
+
wait: async () => ({
|
|
95
|
+
events: [
|
|
96
|
+
{
|
|
97
|
+
args: {
|
|
98
|
+
1: expectedEscrowAddress,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
}),
|
|
103
|
+
}));
|
|
104
|
+
const result = await escrowClient.createEscrow(tokenAddress, trustedHandlers);
|
|
105
|
+
(0, vitest_1.expect)(createEscrowSpy).toHaveBeenCalledWith(tokenAddress, trustedHandlers);
|
|
106
|
+
(0, vitest_1.expect)(result).toBe(expectedEscrowAddress);
|
|
107
|
+
});
|
|
108
|
+
(0, vitest_1.test)('should throw an error if the create an escrow fails', async () => {
|
|
109
|
+
const tokenAddress = ethers_1.ethers.constants.AddressZero;
|
|
110
|
+
const trustedHandlers = [ethers_1.ethers.constants.AddressZero];
|
|
111
|
+
escrowClient.escrowFactoryContract.createEscrow.mockRejectedValueOnce(new Error());
|
|
112
|
+
await (0, vitest_1.expect)(escrowClient.createEscrow(tokenAddress, trustedHandlers)).rejects.toThrow();
|
|
113
|
+
(0, vitest_1.expect)(escrowClient.escrowFactoryContract.createEscrow).toHaveBeenCalledWith(tokenAddress, trustedHandlers);
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
(0, vitest_1.describe)('setup', () => {
|
|
117
|
+
(0, vitest_1.test)('should throw an error if recordingOracle is an invalid address', async () => {
|
|
118
|
+
const escrowConfig = {
|
|
119
|
+
recordingOracle: constants_1.FAKE_ADDRESS,
|
|
120
|
+
reputationOracle: ethers_1.ethers.constants.AddressZero,
|
|
121
|
+
recordingOracleFee: ethers_1.BigNumber.from(10),
|
|
122
|
+
reputationOracleFee: ethers_1.BigNumber.from(10),
|
|
123
|
+
manifestUrl: constants_1.VALID_URL,
|
|
124
|
+
hash: constants_1.FAKE_HASH,
|
|
125
|
+
};
|
|
126
|
+
await (0, vitest_1.expect)(escrowClient.setup(ethers_1.ethers.constants.AddressZero, escrowConfig)).rejects.toThrow(error_1.ErrorInvalidRecordingOracleAddressProvided);
|
|
127
|
+
});
|
|
128
|
+
(0, vitest_1.test)('should throw an error if reputationOracle is an invalid address', async () => {
|
|
129
|
+
const escrowConfig = {
|
|
130
|
+
recordingOracle: ethers_1.ethers.constants.AddressZero,
|
|
131
|
+
reputationOracle: constants_1.FAKE_ADDRESS,
|
|
132
|
+
recordingOracleFee: ethers_1.BigNumber.from(10),
|
|
133
|
+
reputationOracleFee: ethers_1.BigNumber.from(10),
|
|
134
|
+
manifestUrl: constants_1.VALID_URL,
|
|
135
|
+
hash: constants_1.FAKE_HASH,
|
|
136
|
+
};
|
|
137
|
+
await (0, vitest_1.expect)(escrowClient.setup(ethers_1.ethers.constants.AddressZero, escrowConfig)).rejects.toThrow(error_1.ErrorInvalidReputationOracleAddressProvided);
|
|
138
|
+
});
|
|
139
|
+
(0, vitest_1.test)('should throw an error if reputationOracle is an invalid address', async () => {
|
|
140
|
+
const escrowConfig = {
|
|
141
|
+
recordingOracle: ethers_1.ethers.constants.AddressZero,
|
|
142
|
+
reputationOracle: ethers_1.ethers.constants.AddressZero,
|
|
143
|
+
recordingOracleFee: ethers_1.BigNumber.from(10),
|
|
144
|
+
reputationOracleFee: ethers_1.BigNumber.from(10),
|
|
145
|
+
manifestUrl: constants_1.VALID_URL,
|
|
146
|
+
hash: constants_1.FAKE_HASH,
|
|
147
|
+
};
|
|
148
|
+
await (0, vitest_1.expect)(escrowClient.setup(constants_1.FAKE_ADDRESS, escrowConfig)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
149
|
+
});
|
|
150
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
151
|
+
const escrowConfig = {
|
|
152
|
+
recordingOracle: ethers_1.ethers.constants.AddressZero,
|
|
153
|
+
reputationOracle: ethers_1.ethers.constants.AddressZero,
|
|
154
|
+
recordingOracleFee: ethers_1.BigNumber.from(10),
|
|
155
|
+
reputationOracleFee: ethers_1.BigNumber.from(10),
|
|
156
|
+
manifestUrl: constants_1.VALID_URL,
|
|
157
|
+
hash: constants_1.FAKE_HASH,
|
|
158
|
+
};
|
|
159
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
160
|
+
await (0, vitest_1.expect)(escrowClient.setup(ethers_1.ethers.constants.AddressZero, escrowConfig)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
161
|
+
});
|
|
162
|
+
(0, vitest_1.test)('should throw an error if 0 <= recordingOracleFee or 0 <= reputationOracleFee', async () => {
|
|
163
|
+
const escrowConfig = {
|
|
164
|
+
recordingOracle: ethers_1.ethers.constants.AddressZero,
|
|
165
|
+
reputationOracle: ethers_1.ethers.constants.AddressZero,
|
|
166
|
+
recordingOracleFee: ethers_1.BigNumber.from(0),
|
|
167
|
+
reputationOracleFee: ethers_1.BigNumber.from(0),
|
|
168
|
+
manifestUrl: constants_1.VALID_URL,
|
|
169
|
+
hash: constants_1.FAKE_HASH,
|
|
170
|
+
};
|
|
171
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
172
|
+
await (0, vitest_1.expect)(escrowClient.setup(ethers_1.ethers.constants.AddressZero, escrowConfig)).rejects.toThrow(error_1.ErrorAmountMustBeGreaterThanZero);
|
|
173
|
+
});
|
|
174
|
+
(0, vitest_1.test)('should throw an error if recordingOracleFee > 100 or reputationOracleFee > 100', async () => {
|
|
175
|
+
const escrowConfig = {
|
|
176
|
+
recordingOracle: ethers_1.ethers.constants.AddressZero,
|
|
177
|
+
reputationOracle: ethers_1.ethers.constants.AddressZero,
|
|
178
|
+
recordingOracleFee: ethers_1.BigNumber.from(100),
|
|
179
|
+
reputationOracleFee: ethers_1.BigNumber.from(100),
|
|
180
|
+
manifestUrl: constants_1.VALID_URL,
|
|
181
|
+
hash: constants_1.FAKE_HASH,
|
|
182
|
+
};
|
|
183
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
184
|
+
await (0, vitest_1.expect)(escrowClient.setup(ethers_1.ethers.constants.AddressZero, escrowConfig)).rejects.toThrow(error_1.ErrorTotalFeeMustBeLessThanHundred);
|
|
185
|
+
});
|
|
186
|
+
(0, vitest_1.test)('should throw an error if manifestUrl is an empty string', async () => {
|
|
187
|
+
const escrowConfig = {
|
|
188
|
+
recordingOracle: ethers_1.ethers.constants.AddressZero,
|
|
189
|
+
reputationOracle: ethers_1.ethers.constants.AddressZero,
|
|
190
|
+
recordingOracleFee: ethers_1.BigNumber.from(50),
|
|
191
|
+
reputationOracleFee: ethers_1.BigNumber.from(50),
|
|
192
|
+
manifestUrl: '',
|
|
193
|
+
hash: constants_1.FAKE_HASH,
|
|
194
|
+
};
|
|
195
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
196
|
+
await (0, vitest_1.expect)(escrowClient.setup(ethers_1.ethers.constants.AddressZero, escrowConfig)).rejects.toThrow(error_1.ErrorUrlIsEmptyString);
|
|
197
|
+
});
|
|
198
|
+
(0, vitest_1.test)('should throw an error if manifestUrl is an invalid url', async () => {
|
|
199
|
+
const escrowConfig = {
|
|
200
|
+
recordingOracle: ethers_1.ethers.constants.AddressZero,
|
|
201
|
+
reputationOracle: ethers_1.ethers.constants.AddressZero,
|
|
202
|
+
recordingOracleFee: ethers_1.BigNumber.from(50),
|
|
203
|
+
reputationOracleFee: ethers_1.BigNumber.from(50),
|
|
204
|
+
manifestUrl: constants_1.FAKE_URL,
|
|
205
|
+
hash: constants_1.FAKE_HASH,
|
|
206
|
+
};
|
|
207
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
208
|
+
await (0, vitest_1.expect)(escrowClient.setup(ethers_1.ethers.constants.AddressZero, escrowConfig)).rejects.toThrow(error_1.ErrorInvalidUrl);
|
|
209
|
+
});
|
|
210
|
+
(0, vitest_1.test)('should throw an error if hash is an empty string', async () => {
|
|
211
|
+
const escrowConfig = {
|
|
212
|
+
recordingOracle: ethers_1.ethers.constants.AddressZero,
|
|
213
|
+
reputationOracle: ethers_1.ethers.constants.AddressZero,
|
|
214
|
+
recordingOracleFee: ethers_1.BigNumber.from(50),
|
|
215
|
+
reputationOracleFee: ethers_1.BigNumber.from(50),
|
|
216
|
+
manifestUrl: constants_1.VALID_URL,
|
|
217
|
+
hash: '',
|
|
218
|
+
};
|
|
219
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
220
|
+
await (0, vitest_1.expect)(escrowClient.setup(ethers_1.ethers.constants.AddressZero, escrowConfig)).rejects.toThrow(error_1.ErrorHashIsEmptyString);
|
|
221
|
+
});
|
|
222
|
+
(0, vitest_1.test)('should successfully setup escrow', async () => {
|
|
223
|
+
const escrowConfig = {
|
|
224
|
+
recordingOracle: ethers_1.ethers.constants.AddressZero,
|
|
225
|
+
reputationOracle: ethers_1.ethers.constants.AddressZero,
|
|
226
|
+
recordingOracleFee: ethers_1.BigNumber.from(50),
|
|
227
|
+
reputationOracleFee: ethers_1.BigNumber.from(50),
|
|
228
|
+
manifestUrl: constants_1.VALID_URL,
|
|
229
|
+
hash: constants_1.FAKE_HASH,
|
|
230
|
+
};
|
|
231
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
232
|
+
escrowClient.escrowContract.setup.mockReturnValue(true);
|
|
233
|
+
await escrowClient.setup(ethers_1.ethers.constants.AddressZero, escrowConfig);
|
|
234
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.setup).toHaveBeenCalledWith(ethers_1.ethers.constants.AddressZero, ethers_1.ethers.constants.AddressZero, ethers_1.BigNumber.from(50), ethers_1.BigNumber.from(50), constants_1.VALID_URL, constants_1.FAKE_HASH);
|
|
235
|
+
});
|
|
236
|
+
(0, vitest_1.test)('should throw an error if setup escrow fails', async () => {
|
|
237
|
+
const escrowConfig = {
|
|
238
|
+
recordingOracle: ethers_1.ethers.constants.AddressZero,
|
|
239
|
+
reputationOracle: ethers_1.ethers.constants.AddressZero,
|
|
240
|
+
recordingOracleFee: ethers_1.BigNumber.from(50),
|
|
241
|
+
reputationOracleFee: ethers_1.BigNumber.from(50),
|
|
242
|
+
manifestUrl: constants_1.VALID_URL,
|
|
243
|
+
hash: constants_1.FAKE_HASH,
|
|
244
|
+
};
|
|
245
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
246
|
+
escrowClient.escrowContract.setup.mockRejectedValueOnce(new Error());
|
|
247
|
+
await (0, vitest_1.expect)(escrowClient.setup(ethers_1.ethers.constants.AddressZero, escrowConfig)).rejects.toThrow();
|
|
248
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.setup).toHaveBeenCalledWith(ethers_1.ethers.constants.AddressZero, ethers_1.ethers.constants.AddressZero, ethers_1.BigNumber.from(50), ethers_1.BigNumber.from(50), constants_1.VALID_URL, constants_1.FAKE_HASH);
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
(0, vitest_1.describe)('createAndSetupEscrow', () => {
|
|
252
|
+
(0, vitest_1.test)('should successfully create and setup escrow', async () => {
|
|
253
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
254
|
+
const tokenAddress = ethers_1.ethers.constants.AddressZero;
|
|
255
|
+
const trustedHandlers = [ethers_1.ethers.constants.AddressZero];
|
|
256
|
+
const escrowConfig = {
|
|
257
|
+
recordingOracle: ethers_1.ethers.constants.AddressZero,
|
|
258
|
+
reputationOracle: ethers_1.ethers.constants.AddressZero,
|
|
259
|
+
recordingOracleFee: ethers_1.BigNumber.from(50),
|
|
260
|
+
reputationOracleFee: ethers_1.BigNumber.from(50),
|
|
261
|
+
manifestUrl: constants_1.VALID_URL,
|
|
262
|
+
hash: constants_1.FAKE_HASH,
|
|
263
|
+
};
|
|
264
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
265
|
+
escrowClient.createEscrow = vitest_1.vi.fn().mockReturnValue(escrowAddress);
|
|
266
|
+
escrowClient.escrowContract.setup.mockReturnValue(true);
|
|
267
|
+
await escrowClient.createAndSetupEscrow(tokenAddress, trustedHandlers, escrowConfig);
|
|
268
|
+
(0, vitest_1.expect)(escrowClient.createEscrow).toHaveBeenCalledWith(tokenAddress, trustedHandlers);
|
|
269
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.setup).toHaveBeenCalledWith(ethers_1.ethers.constants.AddressZero, ethers_1.ethers.constants.AddressZero, ethers_1.BigNumber.from(50), ethers_1.BigNumber.from(50), constants_1.VALID_URL, constants_1.FAKE_HASH);
|
|
270
|
+
});
|
|
271
|
+
(0, vitest_1.test)('should throw an error if setup escrow fails', async () => {
|
|
272
|
+
const escrowConfig = {
|
|
273
|
+
recordingOracle: ethers_1.ethers.constants.AddressZero,
|
|
274
|
+
reputationOracle: ethers_1.ethers.constants.AddressZero,
|
|
275
|
+
recordingOracleFee: ethers_1.BigNumber.from(50),
|
|
276
|
+
reputationOracleFee: ethers_1.BigNumber.from(50),
|
|
277
|
+
manifestUrl: constants_1.VALID_URL,
|
|
278
|
+
hash: constants_1.FAKE_HASH,
|
|
279
|
+
};
|
|
280
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
281
|
+
escrowClient.escrowContract.setup.mockRejectedValueOnce(new Error());
|
|
282
|
+
await (0, vitest_1.expect)(escrowClient.setup(ethers_1.ethers.constants.AddressZero, escrowConfig)).rejects.toThrow();
|
|
283
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.setup).toHaveBeenCalledWith(ethers_1.ethers.constants.AddressZero, ethers_1.ethers.constants.AddressZero, ethers_1.BigNumber.from(50), ethers_1.BigNumber.from(50), constants_1.VALID_URL, constants_1.FAKE_HASH);
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
(0, vitest_1.describe)('fund', () => {
|
|
287
|
+
(0, vitest_1.test)('should throw an error if escrowAddress is an invalid address', async () => {
|
|
288
|
+
const invalidAddress = constants_1.FAKE_ADDRESS;
|
|
289
|
+
const amount = ethers_1.BigNumber.from(10);
|
|
290
|
+
await (0, vitest_1.expect)(escrowClient.fund(invalidAddress, amount)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
291
|
+
});
|
|
292
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
293
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
294
|
+
const amount = ethers_1.BigNumber.from(10);
|
|
295
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
296
|
+
await (0, vitest_1.expect)(escrowClient.fund(escrowAddress, amount)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
297
|
+
});
|
|
298
|
+
(0, vitest_1.test)('should throw an error if 0 <= amount', async () => {
|
|
299
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
300
|
+
const invalidAmount = ethers_1.BigNumber.from(0);
|
|
301
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
302
|
+
await (0, vitest_1.expect)(escrowClient.fund(escrowAddress, invalidAmount)).rejects.toThrow(error_1.ErrorAmountMustBeGreaterThanZero);
|
|
303
|
+
});
|
|
304
|
+
(0, vitest_1.test)('should successfully fund escrow', async () => {
|
|
305
|
+
const tokenAddress = ethers_1.ethers.constants.AddressZero;
|
|
306
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
307
|
+
const amount = ethers_1.BigNumber.from(10);
|
|
308
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
309
|
+
escrowClient.escrowContract.token.mockReturnValue(tokenAddress);
|
|
310
|
+
await escrowClient.fund(escrowAddress, amount);
|
|
311
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.token).toHaveBeenCalledWith();
|
|
312
|
+
(0, vitest_1.expect)(escrowClient.tokenContract.transfer).toHaveBeenCalledWith(escrowAddress, amount);
|
|
313
|
+
});
|
|
314
|
+
(0, vitest_1.test)('should throw an error if setup escrow fails', async () => {
|
|
315
|
+
const tokenAddress = ethers_1.ethers.constants.AddressZero;
|
|
316
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
317
|
+
const amount = ethers_1.BigNumber.from(10);
|
|
318
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
319
|
+
escrowClient.escrowContract.token.mockReturnValue(tokenAddress);
|
|
320
|
+
escrowClient.tokenContract.transfer.mockRejectedValueOnce(new Error());
|
|
321
|
+
await (0, vitest_1.expect)(escrowClient.fund(escrowAddress, amount)).rejects.toThrow();
|
|
322
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.token).toHaveBeenCalledWith();
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
(0, vitest_1.describe)('storeResults', () => {
|
|
326
|
+
(0, vitest_1.test)('should throw an error if escrowAddress is an invalid address', async () => {
|
|
327
|
+
const invalidAddress = constants_1.FAKE_ADDRESS;
|
|
328
|
+
const url = constants_1.VALID_URL;
|
|
329
|
+
const hash = constants_1.FAKE_HASH;
|
|
330
|
+
await (0, vitest_1.expect)(escrowClient.storeResults(invalidAddress, url, hash)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
331
|
+
});
|
|
332
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
333
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
334
|
+
const url = constants_1.VALID_URL;
|
|
335
|
+
const hash = constants_1.FAKE_HASH;
|
|
336
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
337
|
+
await (0, vitest_1.expect)(escrowClient.storeResults(escrowAddress, url, hash)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
338
|
+
});
|
|
339
|
+
(0, vitest_1.test)('should throw an error if url is an empty string', async () => {
|
|
340
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
341
|
+
const url = '';
|
|
342
|
+
const hash = constants_1.FAKE_HASH;
|
|
343
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
344
|
+
await (0, vitest_1.expect)(escrowClient.storeResults(escrowAddress, url, hash)).rejects.toThrow(error_1.ErrorUrlIsEmptyString);
|
|
345
|
+
});
|
|
346
|
+
(0, vitest_1.test)('should throw an error if results url is invalid url', async () => {
|
|
347
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
348
|
+
const url = constants_1.FAKE_URL;
|
|
349
|
+
const hash = constants_1.FAKE_HASH;
|
|
350
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
351
|
+
await (0, vitest_1.expect)(escrowClient.storeResults(escrowAddress, url, hash)).rejects.toThrow(error_1.ErrorInvalidUrl);
|
|
352
|
+
});
|
|
353
|
+
(0, vitest_1.test)('should throw an error if hash is an empty string', async () => {
|
|
354
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
355
|
+
const url = constants_1.VALID_URL;
|
|
356
|
+
const hash = '';
|
|
357
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
358
|
+
await (0, vitest_1.expect)(escrowClient.storeResults(escrowAddress, url, hash)).rejects.toThrow(error_1.ErrorHashIsEmptyString);
|
|
359
|
+
});
|
|
360
|
+
(0, vitest_1.test)('should successfully store results', async () => {
|
|
361
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
362
|
+
const url = constants_1.VALID_URL;
|
|
363
|
+
const hash = constants_1.FAKE_HASH;
|
|
364
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
365
|
+
await escrowClient.storeResults(escrowAddress, url, hash);
|
|
366
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.storeResults).toHaveBeenCalledWith(url, hash);
|
|
367
|
+
});
|
|
368
|
+
(0, vitest_1.test)('should throw an error if the store results fails', async () => {
|
|
369
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
370
|
+
const url = constants_1.VALID_URL;
|
|
371
|
+
const hash = constants_1.FAKE_HASH;
|
|
372
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
373
|
+
escrowClient.escrowContract.storeResults.mockRejectedValueOnce(new Error());
|
|
374
|
+
await (0, vitest_1.expect)(escrowClient.storeResults(escrowAddress, url, hash)).rejects.toThrow();
|
|
375
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.storeResults).toHaveBeenCalledWith(url, hash);
|
|
376
|
+
});
|
|
377
|
+
});
|
|
378
|
+
(0, vitest_1.describe)('complete', () => {
|
|
379
|
+
(0, vitest_1.test)('should throw an error if escrowAddress is an invalid address', async () => {
|
|
380
|
+
const invalidAddress = constants_1.FAKE_ADDRESS;
|
|
381
|
+
await (0, vitest_1.expect)(escrowClient.complete(invalidAddress)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
382
|
+
});
|
|
383
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
384
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
385
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
386
|
+
await (0, vitest_1.expect)(escrowClient.complete(escrowAddress)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
387
|
+
});
|
|
388
|
+
(0, vitest_1.test)('should successfully complete escrow', async () => {
|
|
389
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
390
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
391
|
+
await escrowClient.complete(escrowAddress);
|
|
392
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.complete).toHaveBeenCalledWith();
|
|
393
|
+
});
|
|
394
|
+
(0, vitest_1.test)('should throw an error if the complete fails', async () => {
|
|
395
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
396
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
397
|
+
escrowClient.escrowContract.complete.mockRejectedValueOnce(new Error());
|
|
398
|
+
await (0, vitest_1.expect)(escrowClient.complete(escrowAddress)).rejects.toThrow();
|
|
399
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.complete).toHaveBeenCalledWith();
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
(0, vitest_1.describe)('bulkPayOut', () => {
|
|
403
|
+
(0, vitest_1.test)('should throw an error if escrowAddress is an invalid address', async () => {
|
|
404
|
+
const invalidAddress = constants_1.FAKE_ADDRESS;
|
|
405
|
+
const recipients = [ethers_1.ethers.constants.AddressZero];
|
|
406
|
+
const amounts = [ethers_1.BigNumber.from(100)];
|
|
407
|
+
const finalResultsUrl = constants_1.VALID_URL;
|
|
408
|
+
const finalResultsHash = constants_1.FAKE_HASH;
|
|
409
|
+
await (0, vitest_1.expect)(escrowClient.bulkPayOut(invalidAddress, recipients, amounts, finalResultsUrl, finalResultsHash)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
410
|
+
});
|
|
411
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
412
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
413
|
+
const recipients = [ethers_1.ethers.constants.AddressZero];
|
|
414
|
+
const amounts = [ethers_1.BigNumber.from(100)];
|
|
415
|
+
const finalResultsUrl = constants_1.VALID_URL;
|
|
416
|
+
const finalResultsHash = constants_1.FAKE_HASH;
|
|
417
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
418
|
+
await (0, vitest_1.expect)(escrowClient.bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
419
|
+
});
|
|
420
|
+
(0, vitest_1.test)('should throw an error if recipients length is equal to 0', async () => {
|
|
421
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
422
|
+
const recipients = [];
|
|
423
|
+
const amounts = [ethers_1.BigNumber.from(100)];
|
|
424
|
+
const finalResultsUrl = constants_1.VALID_URL;
|
|
425
|
+
const finalResultsHash = constants_1.FAKE_HASH;
|
|
426
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
427
|
+
await (0, vitest_1.expect)(escrowClient.bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash)).rejects.toThrow(error_1.ErrorRecipientCannotBeEmptyArray);
|
|
428
|
+
});
|
|
429
|
+
(0, vitest_1.test)('should throw an error if amounts length is equal to 0', async () => {
|
|
430
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
431
|
+
const recipients = [ethers_1.ethers.constants.AddressZero];
|
|
432
|
+
const amounts = [];
|
|
433
|
+
const finalResultsUrl = constants_1.VALID_URL;
|
|
434
|
+
const finalResultsHash = constants_1.FAKE_HASH;
|
|
435
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
436
|
+
await (0, vitest_1.expect)(escrowClient.bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash)).rejects.toThrow(error_1.ErrorAmountsCannotBeEmptyArray);
|
|
437
|
+
});
|
|
438
|
+
(0, vitest_1.test)('should throw an error if recipients and amounts do not have the same length', async () => {
|
|
439
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
440
|
+
const recipients = [ethers_1.ethers.constants.AddressZero];
|
|
441
|
+
const amounts = [
|
|
442
|
+
ethers_1.BigNumber.from(100),
|
|
443
|
+
ethers_1.BigNumber.from(100),
|
|
444
|
+
ethers_1.BigNumber.from(100),
|
|
445
|
+
];
|
|
446
|
+
const finalResultsUrl = constants_1.VALID_URL;
|
|
447
|
+
const finalResultsHash = constants_1.FAKE_HASH;
|
|
448
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
449
|
+
await (0, vitest_1.expect)(escrowClient.bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash)).rejects.toThrow(error_1.ErrorRecipientAndAmountsMustBeSameLength);
|
|
450
|
+
});
|
|
451
|
+
(0, vitest_1.test)('should throw an error if recipients contains invalid addresses', async () => {
|
|
452
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
453
|
+
const recipients = [constants_1.FAKE_ADDRESS];
|
|
454
|
+
const amounts = [ethers_1.BigNumber.from(100)];
|
|
455
|
+
const finalResultsUrl = constants_1.VALID_URL;
|
|
456
|
+
const finalResultsHash = constants_1.FAKE_HASH;
|
|
457
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
458
|
+
await (0, vitest_1.expect)(escrowClient.bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash)).rejects.toThrow(new error_1.InvalidEthereumAddressError(constants_1.FAKE_ADDRESS));
|
|
459
|
+
});
|
|
460
|
+
(0, vitest_1.test)('should throw an error if url is an empty string', async () => {
|
|
461
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
462
|
+
const recipients = [ethers_1.ethers.constants.AddressZero];
|
|
463
|
+
const amounts = [ethers_1.BigNumber.from(100)];
|
|
464
|
+
const finalResultsUrl = '';
|
|
465
|
+
const finalResultsHash = constants_1.FAKE_HASH;
|
|
466
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
467
|
+
await (0, vitest_1.expect)(escrowClient.bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash)).rejects.toThrow(error_1.ErrorUrlIsEmptyString);
|
|
468
|
+
});
|
|
469
|
+
(0, vitest_1.test)('should throw an error if final results url is an invalid url', async () => {
|
|
470
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
471
|
+
const recipients = [ethers_1.ethers.constants.AddressZero];
|
|
472
|
+
const amounts = [ethers_1.BigNumber.from(100)];
|
|
473
|
+
const finalResultsUrl = constants_1.FAKE_URL;
|
|
474
|
+
const finalResultsHash = constants_1.FAKE_HASH;
|
|
475
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
476
|
+
await (0, vitest_1.expect)(escrowClient.bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash)).rejects.toThrow(error_1.ErrorInvalidUrl);
|
|
477
|
+
});
|
|
478
|
+
(0, vitest_1.test)('should throw an error if hash is an empty string', async () => {
|
|
479
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
480
|
+
const recipients = [ethers_1.ethers.constants.AddressZero];
|
|
481
|
+
const amounts = [ethers_1.BigNumber.from(100)];
|
|
482
|
+
const finalResultsUrl = constants_1.VALID_URL;
|
|
483
|
+
const finalResultsHash = '';
|
|
484
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
485
|
+
await (0, vitest_1.expect)(escrowClient.bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash)).rejects.toThrow(error_1.ErrorHashIsEmptyString);
|
|
486
|
+
});
|
|
487
|
+
(0, vitest_1.test)('should throw an error if escrow does not have enough balance', async () => {
|
|
488
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
489
|
+
const recipients = [
|
|
490
|
+
ethers_1.ethers.constants.AddressZero,
|
|
491
|
+
ethers_1.ethers.constants.AddressZero,
|
|
492
|
+
];
|
|
493
|
+
const amounts = [ethers_1.BigNumber.from(90), ethers_1.BigNumber.from(20)];
|
|
494
|
+
const finalResultsUrl = constants_1.VALID_URL;
|
|
495
|
+
const finalResultsHash = constants_1.FAKE_HASH;
|
|
496
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
497
|
+
escrowClient.getBalance = vitest_1.vi.fn().mockReturnValue(ethers_1.BigNumber.from(50));
|
|
498
|
+
await (0, vitest_1.expect)(escrowClient.bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash)).rejects.toThrow(error_1.ErrorEscrowDoesNotHaveEnoughBalance);
|
|
499
|
+
});
|
|
500
|
+
(0, vitest_1.test)('should successfully bulkPayOut escrow', async () => {
|
|
501
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
502
|
+
const recipients = [
|
|
503
|
+
ethers_1.ethers.constants.AddressZero,
|
|
504
|
+
ethers_1.ethers.constants.AddressZero,
|
|
505
|
+
];
|
|
506
|
+
const amounts = [ethers_1.BigNumber.from(10), ethers_1.BigNumber.from(10)];
|
|
507
|
+
const finalResultsUrl = constants_1.VALID_URL;
|
|
508
|
+
const finalResultsHash = constants_1.FAKE_HASH;
|
|
509
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
510
|
+
escrowClient.getBalance = vitest_1.vi.fn().mockReturnValue(ethers_1.BigNumber.from(100));
|
|
511
|
+
await escrowClient.bulkPayOut(escrowAddress, recipients, amounts, finalResultsUrl, finalResultsHash);
|
|
512
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.bulkPayOut).toHaveBeenCalledWith(recipients, amounts, finalResultsUrl, finalResultsHash, constants_2.DEFAULT_TX_ID);
|
|
513
|
+
});
|
|
514
|
+
(0, vitest_1.test)('should throw an error if bulkPayOut fails', async () => {
|
|
515
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
516
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
517
|
+
escrowClient.escrowContract.abort.mockRejectedValueOnce(new Error());
|
|
518
|
+
await (0, vitest_1.expect)(escrowClient.abort(escrowAddress)).rejects.toThrow();
|
|
519
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.abort).toHaveBeenCalledWith();
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
(0, vitest_1.describe)('cancel', () => {
|
|
523
|
+
(0, vitest_1.test)('should throw an error if escrowAddress is an invalid address', async () => {
|
|
524
|
+
const invalidAddress = constants_1.FAKE_ADDRESS;
|
|
525
|
+
await (0, vitest_1.expect)(escrowClient.cancel(invalidAddress)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
526
|
+
});
|
|
527
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
528
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
529
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
530
|
+
await (0, vitest_1.expect)(escrowClient.cancel(escrowAddress)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
531
|
+
});
|
|
532
|
+
(0, vitest_1.test)('should successfully cancel escrow', async () => {
|
|
533
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
534
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
535
|
+
await escrowClient.cancel(escrowAddress);
|
|
536
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.cancel).toHaveBeenCalledWith();
|
|
537
|
+
});
|
|
538
|
+
(0, vitest_1.test)('should throw an error if the cancel fails', async () => {
|
|
539
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
540
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
541
|
+
escrowClient.escrowContract.cancel.mockRejectedValueOnce(new Error());
|
|
542
|
+
await (0, vitest_1.expect)(escrowClient.cancel(escrowAddress)).rejects.toThrow();
|
|
543
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.cancel).toHaveBeenCalledWith();
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
(0, vitest_1.describe)('abort', () => {
|
|
547
|
+
(0, vitest_1.test)('should throw an error if escrowAddress is an invalid address', async () => {
|
|
548
|
+
const invalidAddress = constants_1.FAKE_ADDRESS;
|
|
549
|
+
await (0, vitest_1.expect)(escrowClient.abort(invalidAddress)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
550
|
+
});
|
|
551
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
552
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
553
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
554
|
+
await (0, vitest_1.expect)(escrowClient.abort(escrowAddress)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
555
|
+
});
|
|
556
|
+
(0, vitest_1.test)('should successfully abort escrow', async () => {
|
|
557
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
558
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
559
|
+
await escrowClient.abort(escrowAddress);
|
|
560
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.abort).toHaveBeenCalledWith();
|
|
561
|
+
});
|
|
562
|
+
(0, vitest_1.test)('should throw an error if abort fails', async () => {
|
|
563
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
564
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
565
|
+
escrowClient.escrowContract.abort.mockRejectedValueOnce(new Error());
|
|
566
|
+
await (0, vitest_1.expect)(escrowClient.abort(escrowAddress)).rejects.toThrow();
|
|
567
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.abort).toHaveBeenCalledWith();
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
(0, vitest_1.describe)('addTrustedHandlers', () => {
|
|
571
|
+
(0, vitest_1.test)('should throw an error if escrowAddress is an invalid address', async () => {
|
|
572
|
+
const escrowAddress = constants_1.FAKE_ADDRESS;
|
|
573
|
+
const trustedHandlers = [ethers_1.ethers.constants.AddressZero];
|
|
574
|
+
await (0, vitest_1.expect)(escrowClient.addTrustedHandlers(escrowAddress, trustedHandlers)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
575
|
+
});
|
|
576
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
577
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
578
|
+
const trustedHandlers = [ethers_1.ethers.constants.AddressZero];
|
|
579
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
580
|
+
await (0, vitest_1.expect)(escrowClient.addTrustedHandlers(escrowAddress, trustedHandlers)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
581
|
+
});
|
|
582
|
+
(0, vitest_1.test)('should throw an error if trusted handlers length is equal to 0', async () => {
|
|
583
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
584
|
+
const trustedHandlers = [];
|
|
585
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
586
|
+
await (0, vitest_1.expect)(escrowClient.addTrustedHandlers(escrowAddress, trustedHandlers)).rejects.toThrow(error_1.ErrorListOfHandlersCannotBeEmpty);
|
|
587
|
+
});
|
|
588
|
+
(0, vitest_1.test)('should throw an error if trusted handlers contains invalid addresses', async () => {
|
|
589
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
590
|
+
const trustedHandlers = [constants_1.FAKE_ADDRESS];
|
|
591
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
592
|
+
await (0, vitest_1.expect)(escrowClient.addTrustedHandlers(escrowAddress, trustedHandlers)).rejects.toThrow(new error_1.InvalidEthereumAddressError(constants_1.FAKE_ADDRESS));
|
|
593
|
+
});
|
|
594
|
+
(0, vitest_1.test)('should successfully addTrustedHandlers', async () => {
|
|
595
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
596
|
+
const trustedHandlers = [ethers_1.ethers.constants.AddressZero];
|
|
597
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
598
|
+
await escrowClient.addTrustedHandlers(escrowAddress, trustedHandlers);
|
|
599
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.addTrustedHandlers).toHaveBeenCalledWith(trustedHandlers);
|
|
600
|
+
});
|
|
601
|
+
(0, vitest_1.test)('should throw an error if addTrustedHandlers fails', async () => {
|
|
602
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
603
|
+
const trustedHandlers = [ethers_1.ethers.constants.AddressZero];
|
|
604
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
605
|
+
escrowClient.escrowContract.addTrustedHandlers.mockRejectedValueOnce(new Error());
|
|
606
|
+
await (0, vitest_1.expect)(escrowClient.addTrustedHandlers(escrowAddress, trustedHandlers)).rejects.toThrow();
|
|
607
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.addTrustedHandlers).toHaveBeenCalledWith(trustedHandlers);
|
|
608
|
+
});
|
|
609
|
+
});
|
|
610
|
+
(0, vitest_1.describe)('getBalance', () => {
|
|
611
|
+
(0, vitest_1.test)('should throw an error if escrowAddress is an invalid address', async () => {
|
|
612
|
+
const escrowAddress = constants_1.FAKE_ADDRESS;
|
|
613
|
+
await (0, vitest_1.expect)(escrowClient.getBalance(escrowAddress)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
614
|
+
});
|
|
615
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
616
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
617
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
618
|
+
await (0, vitest_1.expect)(escrowClient.getBalance(escrowAddress)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
619
|
+
});
|
|
620
|
+
(0, vitest_1.test)('should successfully getBalance escrow', async () => {
|
|
621
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
622
|
+
const amount = ethers_1.BigNumber.from(100);
|
|
623
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
624
|
+
escrowClient.escrowContract.getBalance.mockReturnValue(amount);
|
|
625
|
+
const balance = await escrowClient.getBalance(escrowAddress);
|
|
626
|
+
(0, vitest_1.expect)(balance).toEqual(amount);
|
|
627
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.getBalance).toHaveBeenCalledWith();
|
|
628
|
+
});
|
|
629
|
+
(0, vitest_1.test)('should throw an error if the getBalance fails', async () => {
|
|
630
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
631
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
632
|
+
escrowClient.escrowContract.getBalance.mockRejectedValueOnce(new Error());
|
|
633
|
+
await (0, vitest_1.expect)(escrowClient.getBalance(escrowAddress)).rejects.toThrow();
|
|
634
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.getBalance).toHaveBeenCalledWith();
|
|
635
|
+
});
|
|
636
|
+
});
|
|
637
|
+
(0, vitest_1.describe)('getManifestUrl', () => {
|
|
638
|
+
(0, vitest_1.test)('should throw an error if escrowAddress is an invalid address', async () => {
|
|
639
|
+
const escrowAddress = constants_1.FAKE_ADDRESS;
|
|
640
|
+
await (0, vitest_1.expect)(escrowClient.getManifestUrl(escrowAddress)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
641
|
+
});
|
|
642
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
643
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
644
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
645
|
+
await (0, vitest_1.expect)(escrowClient.getManifestUrl(escrowAddress)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
646
|
+
});
|
|
647
|
+
(0, vitest_1.test)('should successfully getManifestUrl', async () => {
|
|
648
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
649
|
+
const url = constants_1.FAKE_URL;
|
|
650
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
651
|
+
escrowClient.escrowContract.manifestUrl.mockReturnValue(url);
|
|
652
|
+
const manifestUrl = await escrowClient.getManifestUrl(escrowAddress);
|
|
653
|
+
(0, vitest_1.expect)(manifestUrl).toEqual(url);
|
|
654
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.manifestUrl).toHaveBeenCalledWith();
|
|
655
|
+
});
|
|
656
|
+
(0, vitest_1.test)('should throw an error if getManifestUrl fails', async () => {
|
|
657
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
658
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
659
|
+
escrowClient.escrowContract.manifestUrl.mockRejectedValueOnce(new Error());
|
|
660
|
+
await (0, vitest_1.expect)(escrowClient.getManifestUrl(escrowAddress)).rejects.toThrow();
|
|
661
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.manifestUrl).toHaveBeenCalledWith();
|
|
662
|
+
});
|
|
663
|
+
});
|
|
664
|
+
(0, vitest_1.describe)('getResultsUrl', () => {
|
|
665
|
+
(0, vitest_1.test)('should throw an error if escrowAddress is an invalid address', async () => {
|
|
666
|
+
const escrowAddress = constants_1.FAKE_ADDRESS;
|
|
667
|
+
await (0, vitest_1.expect)(escrowClient.getResultsUrl(escrowAddress)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
668
|
+
});
|
|
669
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
670
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
671
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
672
|
+
await (0, vitest_1.expect)(escrowClient.getResultsUrl(escrowAddress)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
673
|
+
});
|
|
674
|
+
(0, vitest_1.test)('should successfully getResultsUrl', async () => {
|
|
675
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
676
|
+
const url = constants_1.FAKE_URL;
|
|
677
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
678
|
+
escrowClient.escrowContract.finalResultsUrl.mockReturnValue(url);
|
|
679
|
+
const finalResultsUrl = await escrowClient.getResultsUrl(escrowAddress);
|
|
680
|
+
(0, vitest_1.expect)(finalResultsUrl).toEqual(url);
|
|
681
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.finalResultsUrl).toHaveBeenCalledWith();
|
|
682
|
+
});
|
|
683
|
+
(0, vitest_1.test)('should throw an error if getResultsUrl fails', async () => {
|
|
684
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
685
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
686
|
+
escrowClient.escrowContract.finalResultsUrl.mockRejectedValueOnce(new Error());
|
|
687
|
+
await (0, vitest_1.expect)(escrowClient.getResultsUrl(escrowAddress)).rejects.toThrow();
|
|
688
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.finalResultsUrl).toHaveBeenCalledWith();
|
|
689
|
+
});
|
|
690
|
+
});
|
|
691
|
+
(0, vitest_1.describe)('getTokenAddress', () => {
|
|
692
|
+
(0, vitest_1.test)('should throw an error if escrowAddress is an invalid address', async () => {
|
|
693
|
+
const escrowAddress = constants_1.FAKE_ADDRESS;
|
|
694
|
+
await (0, vitest_1.expect)(escrowClient.getTokenAddress(escrowAddress)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
695
|
+
});
|
|
696
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
697
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
698
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
699
|
+
await (0, vitest_1.expect)(escrowClient.getTokenAddress(escrowAddress)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
700
|
+
});
|
|
701
|
+
(0, vitest_1.test)('should successfully getTokenAddress', async () => {
|
|
702
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
703
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
704
|
+
escrowClient.escrowContract.token.mockReturnValue(ethers_1.ethers.constants.AddressZero);
|
|
705
|
+
const tokenAddress = await escrowClient.getTokenAddress(escrowAddress);
|
|
706
|
+
(0, vitest_1.expect)(tokenAddress).toEqual(ethers_1.ethers.constants.AddressZero);
|
|
707
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.token).toHaveBeenCalledWith();
|
|
708
|
+
});
|
|
709
|
+
(0, vitest_1.test)('should throw an error if getTokenAddress fails', async () => {
|
|
710
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
711
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
712
|
+
escrowClient.escrowContract.token.mockRejectedValueOnce(new Error());
|
|
713
|
+
await (0, vitest_1.expect)(escrowClient.getTokenAddress(escrowAddress)).rejects.toThrow();
|
|
714
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.token).toHaveBeenCalledWith();
|
|
715
|
+
});
|
|
716
|
+
});
|
|
717
|
+
(0, vitest_1.describe)('getStatus', () => {
|
|
718
|
+
(0, vitest_1.test)('should throw an error if escrowAddress is an invalid address', async () => {
|
|
719
|
+
const escrowAddress = constants_1.FAKE_ADDRESS;
|
|
720
|
+
await (0, vitest_1.expect)(escrowClient.getStatus(escrowAddress)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
721
|
+
});
|
|
722
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
723
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
724
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
725
|
+
await (0, vitest_1.expect)(escrowClient.getStatus(escrowAddress)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
726
|
+
});
|
|
727
|
+
(0, vitest_1.test)('should successfully getStatus', async () => {
|
|
728
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
729
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
730
|
+
escrowClient.escrowContract.status.mockReturnValue(types_1.EscrowStatus.Complete);
|
|
731
|
+
const status = await escrowClient.getStatus(escrowAddress);
|
|
732
|
+
(0, vitest_1.expect)(status).toEqual(types_1.EscrowStatus.Complete);
|
|
733
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.status).toHaveBeenCalledWith();
|
|
734
|
+
});
|
|
735
|
+
(0, vitest_1.test)('should throw an error if getStatus fails', async () => {
|
|
736
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
737
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
738
|
+
escrowClient.escrowContract.status.mockRejectedValueOnce(new Error());
|
|
739
|
+
await (0, vitest_1.expect)(escrowClient.getStatus(escrowAddress)).rejects.toThrow();
|
|
740
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.status).toHaveBeenCalledWith();
|
|
741
|
+
});
|
|
742
|
+
});
|
|
743
|
+
(0, vitest_1.describe)('getLaunchedEscrows', () => {
|
|
744
|
+
(0, vitest_1.test)('should throw an error if requesterAddress is an invalid address', async () => {
|
|
745
|
+
const requesterAddress = constants_1.FAKE_ADDRESS;
|
|
746
|
+
await (0, vitest_1.expect)(escrowClient.getLaunchedEscrows(requesterAddress)).rejects.toThrow(error_1.ErrorInvalidAddress);
|
|
747
|
+
});
|
|
748
|
+
(0, vitest_1.test)('should successfully getLaunchedEscrows', async () => {
|
|
749
|
+
const requesterAddress = constants_1.FAKE_ADDRESS;
|
|
750
|
+
const mockLaunchedEscrowsResult = { id: ethers_1.ethers.constants.AddressZero };
|
|
751
|
+
vitest_1.vi.spyOn(escrowClient, 'getLaunchedEscrows').mockImplementation(() => Promise.resolve([mockLaunchedEscrowsResult, mockLaunchedEscrowsResult]));
|
|
752
|
+
const results = await escrowClient.getLaunchedEscrows(requesterAddress);
|
|
753
|
+
(0, vitest_1.expect)(results).toEqual([
|
|
754
|
+
mockLaunchedEscrowsResult,
|
|
755
|
+
mockLaunchedEscrowsResult,
|
|
756
|
+
]);
|
|
757
|
+
});
|
|
758
|
+
});
|
|
759
|
+
(0, vitest_1.describe)('getEscrowsFiltered', () => {
|
|
760
|
+
(0, vitest_1.test)('should throw an error if requesterAddress is an invalid address', async () => {
|
|
761
|
+
const requesterAddress = constants_1.FAKE_ADDRESS;
|
|
762
|
+
await (0, vitest_1.expect)(escrowClient.getEscrowsFiltered(requesterAddress)).rejects.toThrow(error_1.ErrorInvalidAddress);
|
|
763
|
+
});
|
|
764
|
+
(0, vitest_1.test)('should successfully getEscrowsFiltered', async () => {
|
|
765
|
+
const requesterAddress = constants_1.FAKE_ADDRESS;
|
|
766
|
+
const mockLaunchedEscrowsResult = { id: ethers_1.ethers.constants.AddressZero };
|
|
767
|
+
vitest_1.vi.spyOn(escrowClient, 'getEscrowsFiltered').mockImplementation(() => Promise.resolve([mockLaunchedEscrowsResult, mockLaunchedEscrowsResult]));
|
|
768
|
+
const results = await escrowClient.getEscrowsFiltered(requesterAddress);
|
|
769
|
+
(0, vitest_1.expect)(results).toEqual([
|
|
770
|
+
mockLaunchedEscrowsResult,
|
|
771
|
+
mockLaunchedEscrowsResult,
|
|
772
|
+
]);
|
|
773
|
+
});
|
|
774
|
+
});
|
|
775
|
+
(0, vitest_1.describe)('getRecordingOracleAddress', () => {
|
|
776
|
+
(0, vitest_1.test)('should throw an error if escrowAddress is an invalid address', async () => {
|
|
777
|
+
const escrowAddress = constants_1.FAKE_ADDRESS;
|
|
778
|
+
await (0, vitest_1.expect)(escrowClient.getRecordingOracleAddress(escrowAddress)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
779
|
+
});
|
|
780
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
781
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
782
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
783
|
+
await (0, vitest_1.expect)(escrowClient.getRecordingOracleAddress(escrowAddress)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
784
|
+
});
|
|
785
|
+
(0, vitest_1.test)('should successfully getRecordingOracleAddress', async () => {
|
|
786
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
787
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
788
|
+
escrowClient.escrowContract.recordingOracle.mockReturnValue(ethers_1.ethers.constants.AddressZero);
|
|
789
|
+
const recordingOracleAddress = await escrowClient.getRecordingOracleAddress(escrowAddress);
|
|
790
|
+
(0, vitest_1.expect)(recordingOracleAddress).toEqual(ethers_1.ethers.constants.AddressZero);
|
|
791
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.recordingOracle).toHaveBeenCalledWith();
|
|
792
|
+
});
|
|
793
|
+
(0, vitest_1.test)('should throw an error if getRecordingOracleAddress fails', async () => {
|
|
794
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
795
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
796
|
+
escrowClient.escrowContract.recordingOracle.mockRejectedValueOnce(new Error());
|
|
797
|
+
await (0, vitest_1.expect)(escrowClient.getRecordingOracleAddress(escrowAddress)).rejects.toThrow();
|
|
798
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.recordingOracle).toHaveBeenCalledWith();
|
|
799
|
+
});
|
|
800
|
+
});
|
|
801
|
+
(0, vitest_1.describe)('getReputationOracleAddress', () => {
|
|
802
|
+
(0, vitest_1.test)('should throw an error if escrowAddress is an invalid address', async () => {
|
|
803
|
+
const escrowAddress = constants_1.FAKE_ADDRESS;
|
|
804
|
+
await (0, vitest_1.expect)(escrowClient.getReputationOracleAddress(escrowAddress)).rejects.toThrow(error_1.ErrorInvalidEscrowAddressProvided);
|
|
805
|
+
});
|
|
806
|
+
(0, vitest_1.test)('should throw an error if hasEscrow returns false', async () => {
|
|
807
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
808
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(false);
|
|
809
|
+
await (0, vitest_1.expect)(escrowClient.getReputationOracleAddress(escrowAddress)).rejects.toThrow(error_1.ErrorEscrowAddressIsNotProvidedByFactory);
|
|
810
|
+
});
|
|
811
|
+
(0, vitest_1.test)('should successfully getReputationOracleAddress', async () => {
|
|
812
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
813
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
814
|
+
escrowClient.escrowContract.reputationOracle.mockReturnValue(ethers_1.ethers.constants.AddressZero);
|
|
815
|
+
const reputationOracleAddress = await escrowClient.getReputationOracleAddress(escrowAddress);
|
|
816
|
+
(0, vitest_1.expect)(reputationOracleAddress).toEqual(ethers_1.ethers.constants.AddressZero);
|
|
817
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.reputationOracle).toHaveBeenCalledWith();
|
|
818
|
+
});
|
|
819
|
+
(0, vitest_1.test)('should throw an error if getReputationOracleAddress fails', async () => {
|
|
820
|
+
const escrowAddress = ethers_1.ethers.constants.AddressZero;
|
|
821
|
+
escrowClient.escrowFactoryContract.hasEscrow.mockReturnValue(true);
|
|
822
|
+
escrowClient.escrowContract.reputationOracle.mockRejectedValueOnce(new Error());
|
|
823
|
+
await (0, vitest_1.expect)(escrowClient.getReputationOracleAddress(escrowAddress)).rejects.toThrow();
|
|
824
|
+
(0, vitest_1.expect)(escrowClient.escrowContract.reputationOracle).toHaveBeenCalledWith();
|
|
825
|
+
});
|
|
826
|
+
});
|
|
827
|
+
});
|