@human-protocol/sdk 1.0.26 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/error.ts +0 -5
- package/src/job.ts +19 -262
- package/src/storage.ts +3 -4
- package/src/types.ts +0 -13
- package/src/utils.ts +1 -67
- package/test/job.test.ts +69 -133
- package/test/utils/constants.ts +0 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@human-protocol/sdk",
|
|
3
3
|
"description": "Human Protocol SDK",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
7
7
|
"dist",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"clean": "rm -rf ./dist",
|
|
15
15
|
"build": "npm run clean && tsc",
|
|
16
16
|
"prepublish": "npm run build",
|
|
17
|
-
"test": "
|
|
17
|
+
"test": "./scripts/run-test.sh",
|
|
18
18
|
"lint": "eslint .",
|
|
19
19
|
"lint:fix": "eslint . --fix",
|
|
20
20
|
"format": "prettier --write '**/*.{ts,json}'"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
]
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@human-protocol/core": "^1.0.
|
|
41
|
+
"@human-protocol/core": "^1.0.9",
|
|
42
42
|
"aws-sdk": "^2.1255.0",
|
|
43
43
|
"crypto": "^1.0.1",
|
|
44
44
|
"dotenv": "^16.0.3",
|
|
@@ -47,6 +47,6 @@
|
|
|
47
47
|
"winston": "^3.8.2"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"@human-protocol/core": "^1.0.
|
|
50
|
+
"@human-protocol/core": "^1.0.9"
|
|
51
51
|
}
|
|
52
52
|
}
|
package/src/error.ts
CHANGED
|
@@ -36,8 +36,3 @@ export const ErrorHMTokenMissing = new Error('HMToken is missing');
|
|
|
36
36
|
export const ErrorStorageAccessDataMissing = new Error(
|
|
37
37
|
'Storage access data is missing'
|
|
38
38
|
);
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @constant {Error} - The Staking contract is missing.
|
|
42
|
-
*/
|
|
43
|
-
export const ErrorStakingMissing = new Error('Staking contract is missing');
|
package/src/job.ts
CHANGED
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
getEscrow,
|
|
21
21
|
getEscrowFactory,
|
|
22
22
|
getHmToken,
|
|
23
|
-
getStaking,
|
|
24
23
|
toFullDigit,
|
|
25
24
|
} from './utils';
|
|
26
25
|
import {
|
|
@@ -30,7 +29,6 @@ import {
|
|
|
30
29
|
ErrorJobNotLaunched,
|
|
31
30
|
ErrorManifestMissing,
|
|
32
31
|
ErrorReputationOracleMissing,
|
|
33
|
-
ErrorStakingMissing,
|
|
34
32
|
ErrorStorageAccessDataMissing,
|
|
35
33
|
} from './error';
|
|
36
34
|
import { createLogger } from './logger';
|
|
@@ -96,7 +94,6 @@ export class Job {
|
|
|
96
94
|
storageEndpoint,
|
|
97
95
|
storagePublicBucket,
|
|
98
96
|
storageBucket,
|
|
99
|
-
stakingAddr,
|
|
100
97
|
logLevel = 'info',
|
|
101
98
|
}: JobArguments) {
|
|
102
99
|
const provider = network
|
|
@@ -137,7 +134,6 @@ export class Job {
|
|
|
137
134
|
hmTokenAddr,
|
|
138
135
|
escrowAddr,
|
|
139
136
|
factoryAddr,
|
|
140
|
-
stakingAddr,
|
|
141
137
|
};
|
|
142
138
|
|
|
143
139
|
this.manifestData = { manifest };
|
|
@@ -178,21 +174,9 @@ export class Job {
|
|
|
178
174
|
return false;
|
|
179
175
|
}
|
|
180
176
|
|
|
181
|
-
if (!this.contractData.stakingAddr) {
|
|
182
|
-
this._logError(new Error('Staking contract is missing'));
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
this._logger.info('Getting staking...');
|
|
187
|
-
this.contractData.staking = await getStaking(
|
|
188
|
-
this.contractData.stakingAddr,
|
|
189
|
-
this.providerData?.gasPayer
|
|
190
|
-
);
|
|
191
|
-
|
|
192
177
|
this._logger.info('Deploying escrow factory...');
|
|
193
178
|
this.contractData.factory = await deployEscrowFactory(
|
|
194
179
|
this.contractData.hmTokenAddr,
|
|
195
|
-
this.contractData.stakingAddr,
|
|
196
180
|
this.providerData?.gasPayer
|
|
197
181
|
);
|
|
198
182
|
this.contractData.factoryAddr = this.contractData.factory.address;
|
|
@@ -213,31 +197,6 @@ export class Job {
|
|
|
213
197
|
this.providerData?.gasPayer
|
|
214
198
|
);
|
|
215
199
|
|
|
216
|
-
this._logger.info('Checking if staking is configured...');
|
|
217
|
-
const stakingAddr = await this.contractData.factory.staking();
|
|
218
|
-
if (!stakingAddr) {
|
|
219
|
-
this._logError(new Error('Factory is not configured with staking'));
|
|
220
|
-
this.contractData.factory = undefined;
|
|
221
|
-
|
|
222
|
-
return false;
|
|
223
|
-
}
|
|
224
|
-
this._logger.info('Getting staking...');
|
|
225
|
-
this.contractData.staking = await getStaking(
|
|
226
|
-
stakingAddr,
|
|
227
|
-
this.providerData?.gasPayer
|
|
228
|
-
);
|
|
229
|
-
this.contractData.stakingAddr = stakingAddr;
|
|
230
|
-
|
|
231
|
-
this._logger.info('Checking if reward pool is configured...');
|
|
232
|
-
const rewardPoolAddr = await this.contractData.staking.rewardPool();
|
|
233
|
-
if (!rewardPoolAddr) {
|
|
234
|
-
this._logError(new Error('Staking is not configured with reward pool'));
|
|
235
|
-
this.contractData.staking = undefined;
|
|
236
|
-
this.contractData.factory = undefined;
|
|
237
|
-
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
200
|
this._logger.info('Checking if escrow exists in the factory...');
|
|
242
201
|
const hasEscrow = await this.contractData?.factory.hasEscrow(
|
|
243
202
|
this.contractData?.escrowAddr
|
|
@@ -315,32 +274,26 @@ export class Job {
|
|
|
315
274
|
|
|
316
275
|
this._logger.info('Launching escrow...');
|
|
317
276
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
);
|
|
277
|
+
const txReceipt = await this.contractData?.factory?.createEscrow(
|
|
278
|
+
this.providerData?.trustedHandlers?.map(
|
|
279
|
+
(trustedHandler) => trustedHandler.address
|
|
280
|
+
) || []
|
|
281
|
+
);
|
|
324
282
|
|
|
325
|
-
|
|
283
|
+
const txResponse = await txReceipt?.wait();
|
|
326
284
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
);
|
|
285
|
+
const event = txResponse?.events?.find(
|
|
286
|
+
(event) => event.event === 'Launched'
|
|
287
|
+
);
|
|
331
288
|
|
|
332
|
-
|
|
333
|
-
|
|
289
|
+
const escrowAddr = event?.args?.[1];
|
|
290
|
+
this._logger.info(`Escrow is deployed at ${escrowAddr}.`);
|
|
334
291
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
} catch {
|
|
341
|
-
this._logError(new Error('Error creating escrow...'));
|
|
342
|
-
return false;
|
|
343
|
-
}
|
|
292
|
+
this.contractData.escrowAddr = escrowAddr;
|
|
293
|
+
this.contractData.escrow = await getEscrow(
|
|
294
|
+
escrowAddr,
|
|
295
|
+
this.providerData?.gasPayer
|
|
296
|
+
);
|
|
344
297
|
|
|
345
298
|
return (
|
|
346
299
|
(await this.status()) == EscrowStatus.Launched &&
|
|
@@ -680,184 +633,6 @@ export class Job {
|
|
|
680
633
|
return (await this.status()) === EscrowStatus.Complete;
|
|
681
634
|
}
|
|
682
635
|
|
|
683
|
-
/**
|
|
684
|
-
* **Stake HMTokens**
|
|
685
|
-
*
|
|
686
|
-
* @param {number} amount - Amount to stake
|
|
687
|
-
* @param {string | undefined} from - Address to stake
|
|
688
|
-
* @returns {Promise<boolean>} - True if the token is staked
|
|
689
|
-
*/
|
|
690
|
-
async stake(amount: number, from?: string) {
|
|
691
|
-
if (!this.contractData?.staking) {
|
|
692
|
-
this._logError(ErrorStakingMissing);
|
|
693
|
-
return false;
|
|
694
|
-
}
|
|
695
|
-
if (!this.contractData.hmToken) {
|
|
696
|
-
this._logError(ErrorHMTokenMissing);
|
|
697
|
-
return false;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
const operator = this._findOperator(from);
|
|
701
|
-
|
|
702
|
-
if (!operator) {
|
|
703
|
-
this._logError(new Error('Unknown wallet'));
|
|
704
|
-
return false;
|
|
705
|
-
}
|
|
706
|
-
|
|
707
|
-
try {
|
|
708
|
-
const approved = await this.contractData.hmToken
|
|
709
|
-
.connect(operator)
|
|
710
|
-
.approve(this.contractData.staking.address, toFullDigit(amount));
|
|
711
|
-
|
|
712
|
-
if (!approved) {
|
|
713
|
-
throw new Error('Not approved');
|
|
714
|
-
}
|
|
715
|
-
} catch {
|
|
716
|
-
this._logError(new Error('Error approving HMTokens for staking'));
|
|
717
|
-
return false;
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
try {
|
|
721
|
-
await this.contractData.staking
|
|
722
|
-
.connect(operator)
|
|
723
|
-
.stake(toFullDigit(amount));
|
|
724
|
-
} catch {
|
|
725
|
-
this._logError(new Error(`Error executing transaction from ${from}`));
|
|
726
|
-
return false;
|
|
727
|
-
}
|
|
728
|
-
return true;
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
/**
|
|
732
|
-
* **Unstake HMTokens**
|
|
733
|
-
*
|
|
734
|
-
* @param {number} amount - Amount to unstake
|
|
735
|
-
* @param {string | undefined} from - Address to unstake
|
|
736
|
-
* @returns {Promise<boolean>} - True if the token is unstaked
|
|
737
|
-
*/
|
|
738
|
-
async unstake(amount: number, from?: string) {
|
|
739
|
-
if (!this.contractData?.staking) {
|
|
740
|
-
this._logError(ErrorStakingMissing);
|
|
741
|
-
return false;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
const operator = this._findOperator(from);
|
|
745
|
-
|
|
746
|
-
if (!operator) {
|
|
747
|
-
this._logError(new Error('Unknown wallet'));
|
|
748
|
-
return false;
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
try {
|
|
752
|
-
await this.contractData.staking
|
|
753
|
-
.connect(operator)
|
|
754
|
-
.unstake(toFullDigit(amount));
|
|
755
|
-
} catch {
|
|
756
|
-
this._logError(new Error(`Error executing transaction from ${from}`));
|
|
757
|
-
return false;
|
|
758
|
-
}
|
|
759
|
-
return true;
|
|
760
|
-
}
|
|
761
|
-
|
|
762
|
-
/**
|
|
763
|
-
* **Withdraw unstaked HMTokens**
|
|
764
|
-
*
|
|
765
|
-
* @param {string | undefined} from - Address to withdraw
|
|
766
|
-
* @returns {Promise<boolean>} - True if the token is withdrawn
|
|
767
|
-
*/
|
|
768
|
-
async withdraw(from?: string) {
|
|
769
|
-
if (!this.contractData?.staking) {
|
|
770
|
-
this._logError(ErrorStakingMissing);
|
|
771
|
-
return false;
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
const operator = this._findOperator(from);
|
|
775
|
-
|
|
776
|
-
if (!operator) {
|
|
777
|
-
this._logError(new Error('Unknown wallet'));
|
|
778
|
-
return false;
|
|
779
|
-
}
|
|
780
|
-
|
|
781
|
-
try {
|
|
782
|
-
await this.contractData.staking.connect(operator).withdraw();
|
|
783
|
-
} catch {
|
|
784
|
-
this._logError(new Error(`Error executing transaction from ${from}`));
|
|
785
|
-
return false;
|
|
786
|
-
}
|
|
787
|
-
return true;
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
/**
|
|
791
|
-
* **Allocate HMTokens staked to the job**
|
|
792
|
-
*
|
|
793
|
-
* @param {number} amount - Amount to allocate
|
|
794
|
-
* @param {string | undefined} - Address to allocate with
|
|
795
|
-
* @returns {Promise<boolean>} - True if the token is allocated
|
|
796
|
-
*/
|
|
797
|
-
async allocate(amount: number, from?: string) {
|
|
798
|
-
if (!this.contractData?.staking) {
|
|
799
|
-
this._logError(ErrorStakingMissing);
|
|
800
|
-
return false;
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
if (!this.contractData.escrowAddr) {
|
|
804
|
-
this._logError(ErrorJobNotLaunched);
|
|
805
|
-
return false;
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
const operator = this._findOperator(from);
|
|
809
|
-
|
|
810
|
-
if (!operator) {
|
|
811
|
-
this._logError(new Error('Unknown wallet'));
|
|
812
|
-
return false;
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
try {
|
|
816
|
-
await this.contractData.staking
|
|
817
|
-
.connect(operator)
|
|
818
|
-
.allocate(this.contractData.escrowAddr, toFullDigit(amount));
|
|
819
|
-
} catch {
|
|
820
|
-
this._logError(new Error(`Error executing transaction from ${from}`));
|
|
821
|
-
return false;
|
|
822
|
-
}
|
|
823
|
-
return true;
|
|
824
|
-
}
|
|
825
|
-
|
|
826
|
-
/**
|
|
827
|
-
* **Unallocate HMTokens from the job**
|
|
828
|
-
*
|
|
829
|
-
* @param {string | undefined} - Address to close allocation with
|
|
830
|
-
* @returns {Promise<boolean>} - True if the token is unallocated.
|
|
831
|
-
*/
|
|
832
|
-
async closeAllocation(from?: string) {
|
|
833
|
-
if (!this.contractData?.staking) {
|
|
834
|
-
this._logError(ErrorStakingMissing);
|
|
835
|
-
return false;
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
if (!this.contractData.escrowAddr) {
|
|
839
|
-
this._logError(ErrorJobNotLaunched);
|
|
840
|
-
return false;
|
|
841
|
-
}
|
|
842
|
-
|
|
843
|
-
const operator = this._findOperator(from);
|
|
844
|
-
|
|
845
|
-
if (!operator) {
|
|
846
|
-
this._logError(new Error('Unknown wallet'));
|
|
847
|
-
return false;
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
try {
|
|
851
|
-
await this.contractData.staking
|
|
852
|
-
.connect(operator)
|
|
853
|
-
.closeAllocation(this.contractData.escrowAddr);
|
|
854
|
-
} catch {
|
|
855
|
-
this._logError(new Error(`Error executing transaction from ${from}`));
|
|
856
|
-
return false;
|
|
857
|
-
}
|
|
858
|
-
return true;
|
|
859
|
-
}
|
|
860
|
-
|
|
861
636
|
/**
|
|
862
637
|
* **Get current status of the escrow**
|
|
863
638
|
*
|
|
@@ -1028,10 +803,8 @@ export class Job {
|
|
|
1028
803
|
await contract.connect(trustedHandler).functions[functionName](...args);
|
|
1029
804
|
return true;
|
|
1030
805
|
} catch (err) {
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
'Error executing the transaction from all of the trusted handlers. Stop continue executing...'
|
|
1034
|
-
)
|
|
806
|
+
new Error(
|
|
807
|
+
'Error executing the transaction from all of the trusted handlers. Stop continue executing...'
|
|
1035
808
|
);
|
|
1036
809
|
}
|
|
1037
810
|
}
|
|
@@ -1040,25 +813,9 @@ export class Job {
|
|
|
1040
813
|
|
|
1041
814
|
/**
|
|
1042
815
|
* **Error log**
|
|
1043
|
-
*
|
|
1044
816
|
* @param {Error} error - Occured error
|
|
1045
817
|
*/
|
|
1046
|
-
private _logError(error: Error) {
|
|
818
|
+
private async _logError(error: Error) {
|
|
1047
819
|
this._logger.error(error.message);
|
|
1048
820
|
}
|
|
1049
|
-
|
|
1050
|
-
/**
|
|
1051
|
-
* **Find operator to execute tx**
|
|
1052
|
-
*
|
|
1053
|
-
* @param {string} addr - Address of the operator
|
|
1054
|
-
* @returns {ethers.Wallet | undefined} - Operator wallet
|
|
1055
|
-
*/
|
|
1056
|
-
private _findOperator(addr?: string): ethers.Wallet | undefined {
|
|
1057
|
-
return addr
|
|
1058
|
-
? [
|
|
1059
|
-
this.providerData?.gasPayer,
|
|
1060
|
-
...(this.providerData?.trustedHandlers || []),
|
|
1061
|
-
].find((account?: ethers.Wallet) => account?.address === addr)
|
|
1062
|
-
: this.providerData?.gasPayer;
|
|
1063
|
-
}
|
|
1064
821
|
}
|
package/src/storage.ts
CHANGED
|
@@ -76,7 +76,7 @@ export const getKeyFromURL = (url: string): string => {
|
|
|
76
76
|
* @param {StorageAccessData} storageAccessData - Cloud storage access data
|
|
77
77
|
* @param {string} key - Key of result object
|
|
78
78
|
* @param {string} privateKey - Private key to decode encrypted content
|
|
79
|
-
* @param {
|
|
79
|
+
* @param {string} isPublic - Whether the objest is using public bucket, or private bucket
|
|
80
80
|
* @returns {Promise<Result>} - Downloaded result
|
|
81
81
|
*/
|
|
82
82
|
export const download = async (
|
|
@@ -104,15 +104,14 @@ export const download = async (
|
|
|
104
104
|
* @param {StorageAccessData} storageAccessData - Cloud storage access data
|
|
105
105
|
* @param {Result} result - Result to upload
|
|
106
106
|
* @param {string} publicKey - Public key to encrypt data if necessary
|
|
107
|
-
* @param {
|
|
108
|
-
* @param {
|
|
107
|
+
* @param {string} encrypt - Whether to encrypt the result, or not
|
|
108
|
+
* @param {string} isPublic - Whether to use public bucket, or private bucket
|
|
109
109
|
* @returns {Promise<UploadResult>} - Uploaded result with key/hash
|
|
110
110
|
*/
|
|
111
111
|
export const upload = async (
|
|
112
112
|
storageAccessData: StorageAccessData,
|
|
113
113
|
result: Result,
|
|
114
114
|
publicKey: string,
|
|
115
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
116
115
|
encrypt = true,
|
|
117
116
|
isPublic = false
|
|
118
117
|
): Promise<UploadResult> => {
|
package/src/types.ts
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
Escrow,
|
|
3
3
|
EscrowFactory,
|
|
4
4
|
HMToken,
|
|
5
|
-
Staking,
|
|
6
5
|
} from '@human-protocol/core/typechain-types';
|
|
7
6
|
import { ethers } from 'ethers';
|
|
8
7
|
|
|
@@ -568,14 +567,6 @@ export type ContractData = {
|
|
|
568
567
|
* HMToken contract instance
|
|
569
568
|
*/
|
|
570
569
|
hmToken?: HMToken;
|
|
571
|
-
/**
|
|
572
|
-
* Staking contract address
|
|
573
|
-
*/
|
|
574
|
-
stakingAddr?: string;
|
|
575
|
-
/**
|
|
576
|
-
* Staking contract instance
|
|
577
|
-
*/
|
|
578
|
-
staking?: Staking;
|
|
579
570
|
};
|
|
580
571
|
|
|
581
572
|
/**
|
|
@@ -636,10 +627,6 @@ export type JobArguments = {
|
|
|
636
627
|
/**
|
|
637
628
|
* Factory contract address
|
|
638
629
|
*/
|
|
639
|
-
stakingAddr?: string;
|
|
640
|
-
/**
|
|
641
|
-
* Staking contract address
|
|
642
|
-
*/
|
|
643
630
|
factoryAddr?: string;
|
|
644
631
|
/**
|
|
645
632
|
* Escrow contract address
|
package/src/utils.ts
CHANGED
|
@@ -7,10 +7,6 @@ import {
|
|
|
7
7
|
EscrowFactory__factory,
|
|
8
8
|
HMToken,
|
|
9
9
|
HMToken__factory,
|
|
10
|
-
Staking,
|
|
11
|
-
Staking__factory,
|
|
12
|
-
RewardPool,
|
|
13
|
-
RewardPool__factory,
|
|
14
10
|
} from '@human-protocol/core/typechain-types';
|
|
15
11
|
|
|
16
12
|
/**
|
|
@@ -35,18 +31,16 @@ export const getHmToken = async (
|
|
|
35
31
|
* **Deploy EscrowFactory contract**
|
|
36
32
|
*
|
|
37
33
|
* @param {string} hmTokenAddr HMToken address
|
|
38
|
-
* @param {string} stakingAddr Staking address
|
|
39
34
|
* @param {ethers.Signer | undefined} signer Deployer signer
|
|
40
35
|
* @returns {Promise<EscrowFactory>} Deployed contract instance
|
|
41
36
|
*/
|
|
42
37
|
export const deployEscrowFactory = async (
|
|
43
38
|
hmTokenAddr: string,
|
|
44
|
-
stakingAddr: string,
|
|
45
39
|
signer?: ethers.Signer
|
|
46
40
|
): Promise<EscrowFactory> => {
|
|
47
41
|
const factory = new EscrowFactory__factory(signer);
|
|
48
42
|
|
|
49
|
-
const contract = await factory.deploy(hmTokenAddr
|
|
43
|
+
const contract = await factory.deploy(hmTokenAddr);
|
|
50
44
|
|
|
51
45
|
return contract;
|
|
52
46
|
};
|
|
@@ -87,66 +81,6 @@ export const getEscrow = async (
|
|
|
87
81
|
return contract;
|
|
88
82
|
};
|
|
89
83
|
|
|
90
|
-
/**
|
|
91
|
-
* **Deploy Staking contract**
|
|
92
|
-
*
|
|
93
|
-
* @param {string} hmTokenAddr HMToken address
|
|
94
|
-
* @param {number} minimumStake Minimum amount to stake
|
|
95
|
-
* @param {number} lockPeriod Lock period after unstake
|
|
96
|
-
* @param {ethers.Signer | undefined} signer Deployer signer
|
|
97
|
-
* @returns {Promise<Staking>} Deployed contract instance
|
|
98
|
-
*/
|
|
99
|
-
export const deployStaking = async (
|
|
100
|
-
hmTokenAddr: string,
|
|
101
|
-
minimumStake: number,
|
|
102
|
-
lockPeriod: number,
|
|
103
|
-
signer?: ethers.Signer
|
|
104
|
-
): Promise<Staking> => {
|
|
105
|
-
const staking = new Staking__factory(signer);
|
|
106
|
-
const contract = await staking.deploy(hmTokenAddr, minimumStake, lockPeriod);
|
|
107
|
-
|
|
108
|
-
return contract;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* **Get Staking contract instance at given address**
|
|
113
|
-
*
|
|
114
|
-
* @param {string} stakingAddr Staking contract address
|
|
115
|
-
* @param {ethers.Signer | undefined} signer Deployer signer
|
|
116
|
-
* @returns {Promise<Staking>} Attached contract instance
|
|
117
|
-
*/
|
|
118
|
-
export const getStaking = async (
|
|
119
|
-
stakingAddr: string,
|
|
120
|
-
signer?: ethers.Signer
|
|
121
|
-
): Promise<Staking> => {
|
|
122
|
-
const factory = new Staking__factory(signer);
|
|
123
|
-
|
|
124
|
-
const contract = await factory.attach(stakingAddr);
|
|
125
|
-
|
|
126
|
-
return contract;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* **Deploy RewardPool contract**
|
|
131
|
-
*
|
|
132
|
-
* @param {string} hmTokenAddr HMToken address
|
|
133
|
-
* @param {string} stakingAddr Staking address
|
|
134
|
-
* @param {number} fee Reward fee of the protocol
|
|
135
|
-
* @param {ethers.Signer | undefined} signer Deployer signer
|
|
136
|
-
* @returns {Promise<Staking>} Deployed contract instance
|
|
137
|
-
*/
|
|
138
|
-
export const deployRewardPool = async (
|
|
139
|
-
hmTokenAddr: string,
|
|
140
|
-
stakingAddr: string,
|
|
141
|
-
fee: number,
|
|
142
|
-
signer?: ethers.Signer
|
|
143
|
-
): Promise<RewardPool> => {
|
|
144
|
-
const rewardPool = new RewardPool__factory(signer);
|
|
145
|
-
const contract = await rewardPool.deploy(hmTokenAddr, stakingAddr, fee);
|
|
146
|
-
|
|
147
|
-
return contract;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
84
|
/**
|
|
151
85
|
* **Get specific amount representation in given decimals**
|
|
152
86
|
*
|
package/test/job.test.ts
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
DEFAULT_GAS_PAYER_ADDR,
|
|
7
7
|
DEFAULT_GAS_PAYER_PRIVKEY,
|
|
8
8
|
DEFAULT_HMTOKEN_ADDR,
|
|
9
|
-
DEFAULT_STAKING_ADDR,
|
|
10
9
|
NOT_TRUSTED_OPERATOR_PRIVKEY,
|
|
11
10
|
REPUTATION_ORACLE_PRIVKEY,
|
|
12
11
|
TRUSTED_OPERATOR1_ADDR,
|
|
@@ -30,12 +29,6 @@ jest.mock('../src/storage', () => ({
|
|
|
30
29
|
getPublicURL: jest.fn().mockResolvedValue('public-url'),
|
|
31
30
|
}));
|
|
32
31
|
|
|
33
|
-
const setupJob = async (job: Job) => {
|
|
34
|
-
await job.initialize();
|
|
35
|
-
await job.launch();
|
|
36
|
-
await job.setup();
|
|
37
|
-
};
|
|
38
|
-
|
|
39
32
|
describe('Test Job', () => {
|
|
40
33
|
describe('New job', () => {
|
|
41
34
|
let job: Job;
|
|
@@ -46,8 +39,7 @@ describe('Test Job', () => {
|
|
|
46
39
|
reputationOracle: REPUTATION_ORACLE_PRIVKEY,
|
|
47
40
|
manifest: manifest,
|
|
48
41
|
hmTokenAddr: DEFAULT_HMTOKEN_ADDR,
|
|
49
|
-
|
|
50
|
-
logLevel: 'error',
|
|
42
|
+
logLevel: 'debug',
|
|
51
43
|
});
|
|
52
44
|
});
|
|
53
45
|
|
|
@@ -62,11 +54,11 @@ describe('Test Job', () => {
|
|
|
62
54
|
expect(await job.contractData?.factory?.address).not.toBeNull();
|
|
63
55
|
});
|
|
64
56
|
|
|
65
|
-
it('Should be able to launch the job
|
|
66
|
-
|
|
57
|
+
it('Should be able to launch the job', async () => {
|
|
58
|
+
// Fail to launch the job before initialization
|
|
67
59
|
expect(await job.launch()).toBe(false);
|
|
68
60
|
|
|
69
|
-
await job.
|
|
61
|
+
await job.initialize();
|
|
70
62
|
|
|
71
63
|
expect(await job.launch()).toBe(true);
|
|
72
64
|
expect(await job.status()).toBe(EscrowStatus.Launched);
|
|
@@ -100,7 +92,9 @@ describe('Test Job', () => {
|
|
|
100
92
|
});
|
|
101
93
|
|
|
102
94
|
it('Should be able to bulk payout workers', async () => {
|
|
103
|
-
await
|
|
95
|
+
await job.initialize();
|
|
96
|
+
await job.launch();
|
|
97
|
+
await job.setup();
|
|
104
98
|
|
|
105
99
|
expect(
|
|
106
100
|
await job.bulkPayout(
|
|
@@ -154,7 +148,9 @@ describe('Test Job', () => {
|
|
|
154
148
|
});
|
|
155
149
|
|
|
156
150
|
it('Should encrypt result, when bulk paying out workers', async () => {
|
|
157
|
-
await
|
|
151
|
+
await job.initialize();
|
|
152
|
+
await job.launch();
|
|
153
|
+
await job.setup();
|
|
158
154
|
|
|
159
155
|
jest.clearAllMocks();
|
|
160
156
|
const finalResults = { results: 0 };
|
|
@@ -180,7 +176,9 @@ describe('Test Job', () => {
|
|
|
180
176
|
});
|
|
181
177
|
|
|
182
178
|
it('Should not encrypt result, when bulk paying out workers', async () => {
|
|
183
|
-
await
|
|
179
|
+
await job.initialize();
|
|
180
|
+
await job.launch();
|
|
181
|
+
await job.setup();
|
|
184
182
|
|
|
185
183
|
jest.clearAllMocks();
|
|
186
184
|
const finalResults = { results: 0 };
|
|
@@ -206,7 +204,9 @@ describe('Test Job', () => {
|
|
|
206
204
|
});
|
|
207
205
|
|
|
208
206
|
it('Should store result in private storage, when bulk paying out workers', async () => {
|
|
209
|
-
await
|
|
207
|
+
await job.initialize();
|
|
208
|
+
await job.launch();
|
|
209
|
+
await job.setup();
|
|
210
210
|
|
|
211
211
|
jest.clearAllMocks();
|
|
212
212
|
const finalResults = { results: 0 };
|
|
@@ -233,7 +233,9 @@ describe('Test Job', () => {
|
|
|
233
233
|
});
|
|
234
234
|
|
|
235
235
|
it('Should store result in public storage, when bulk paying out workers', async () => {
|
|
236
|
-
await
|
|
236
|
+
await job.initialize();
|
|
237
|
+
await job.launch();
|
|
238
|
+
await job.setup();
|
|
237
239
|
|
|
238
240
|
jest.clearAllMocks();
|
|
239
241
|
const finalResults = { results: 0 };
|
|
@@ -261,7 +263,9 @@ describe('Test Job', () => {
|
|
|
261
263
|
});
|
|
262
264
|
|
|
263
265
|
it('Should return final result', async () => {
|
|
264
|
-
await
|
|
266
|
+
await job.initialize();
|
|
267
|
+
await job.launch();
|
|
268
|
+
await job.setup();
|
|
265
269
|
|
|
266
270
|
const finalResults = { results: 0 };
|
|
267
271
|
await job.bulkPayout(
|
|
@@ -281,13 +285,17 @@ describe('Test Job', () => {
|
|
|
281
285
|
});
|
|
282
286
|
|
|
283
287
|
it('Should be able to abort the job', async () => {
|
|
284
|
-
await
|
|
288
|
+
await job.initialize();
|
|
289
|
+
await job.launch();
|
|
290
|
+
await job.setup();
|
|
285
291
|
|
|
286
292
|
expect(await job.abort()).toBe(true);
|
|
287
293
|
});
|
|
288
294
|
|
|
289
295
|
it('Should be able to abort partially paid job', async () => {
|
|
290
|
-
await
|
|
296
|
+
await job.initialize();
|
|
297
|
+
await job.launch();
|
|
298
|
+
await job.setup();
|
|
291
299
|
|
|
292
300
|
const finalResults = { results: 0 };
|
|
293
301
|
await job.bulkPayout(
|
|
@@ -305,7 +313,9 @@ describe('Test Job', () => {
|
|
|
305
313
|
});
|
|
306
314
|
|
|
307
315
|
it('Should not be able to abort fully paid job', async () => {
|
|
308
|
-
await
|
|
316
|
+
await job.initialize();
|
|
317
|
+
await job.launch();
|
|
318
|
+
await job.setup();
|
|
309
319
|
|
|
310
320
|
const finalResults = { results: 0 };
|
|
311
321
|
await job.bulkPayout(
|
|
@@ -323,14 +333,18 @@ describe('Test Job', () => {
|
|
|
323
333
|
});
|
|
324
334
|
|
|
325
335
|
it('Should be able to cancel the job', async () => {
|
|
326
|
-
await
|
|
336
|
+
await job.initialize();
|
|
337
|
+
await job.launch();
|
|
338
|
+
await job.setup();
|
|
327
339
|
|
|
328
340
|
expect(await job.cancel()).toBe(true);
|
|
329
341
|
expect((await job.balance())?.toString()).toBe(toFullDigit(0).toString());
|
|
330
342
|
});
|
|
331
343
|
|
|
332
344
|
it('Should be able to cancel partially paid job', async () => {
|
|
333
|
-
await
|
|
345
|
+
await job.initialize();
|
|
346
|
+
await job.launch();
|
|
347
|
+
await job.setup();
|
|
334
348
|
|
|
335
349
|
const finalResults = { results: 0 };
|
|
336
350
|
await job.bulkPayout(
|
|
@@ -349,7 +363,9 @@ describe('Test Job', () => {
|
|
|
349
363
|
});
|
|
350
364
|
|
|
351
365
|
it('Should not be able to cancel paid job', async () => {
|
|
352
|
-
await
|
|
366
|
+
await job.initialize();
|
|
367
|
+
await job.launch();
|
|
368
|
+
await job.setup();
|
|
353
369
|
|
|
354
370
|
const finalResults = { results: 0 };
|
|
355
371
|
await job.bulkPayout(
|
|
@@ -365,81 +381,6 @@ describe('Test Job', () => {
|
|
|
365
381
|
|
|
366
382
|
expect(await job.cancel()).toBe(false);
|
|
367
383
|
});
|
|
368
|
-
|
|
369
|
-
it('Should be able to allocate token to the job', async () => {
|
|
370
|
-
await job.initialize();
|
|
371
|
-
|
|
372
|
-
expect(await job.launch()).toBe(true);
|
|
373
|
-
expect(await job.status()).toBe(EscrowStatus.Launched);
|
|
374
|
-
|
|
375
|
-
expect(await job.allocate(1)).toBe(true);
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
it('Should be able to launch another job after allocating portion of the stake', async () => {
|
|
379
|
-
await job.initialize();
|
|
380
|
-
await job.stake(2);
|
|
381
|
-
|
|
382
|
-
expect(await job.launch()).toBe(true);
|
|
383
|
-
expect(await job.status()).toBe(EscrowStatus.Launched);
|
|
384
|
-
|
|
385
|
-
expect(await job.allocate(1)).toBe(true);
|
|
386
|
-
|
|
387
|
-
const newJob = new Job({
|
|
388
|
-
gasPayer: DEFAULT_GAS_PAYER_PRIVKEY,
|
|
389
|
-
reputationOracle: REPUTATION_ORACLE_PRIVKEY,
|
|
390
|
-
manifest: manifest,
|
|
391
|
-
hmTokenAddr: DEFAULT_HMTOKEN_ADDR,
|
|
392
|
-
stakingAddr: DEFAULT_STAKING_ADDR,
|
|
393
|
-
logLevel: 'error',
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
await newJob.initialize();
|
|
397
|
-
expect(await newJob.launch()).toBe(true);
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
it('Should not be able to launch another job after allocating all of the stake', async () => {
|
|
401
|
-
await job.initialize();
|
|
402
|
-
|
|
403
|
-
expect(await job.launch()).toBe(true);
|
|
404
|
-
expect(await job.status()).toBe(EscrowStatus.Launched);
|
|
405
|
-
|
|
406
|
-
expect(await job.allocate(1)).toBe(true);
|
|
407
|
-
|
|
408
|
-
const newJob = new Job({
|
|
409
|
-
gasPayer: DEFAULT_GAS_PAYER_PRIVKEY,
|
|
410
|
-
reputationOracle: REPUTATION_ORACLE_PRIVKEY,
|
|
411
|
-
manifest: manifest,
|
|
412
|
-
hmTokenAddr: DEFAULT_HMTOKEN_ADDR,
|
|
413
|
-
stakingAddr: DEFAULT_STAKING_ADDR,
|
|
414
|
-
logLevel: 'error',
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
await newJob.initialize();
|
|
418
|
-
expect(await newJob.launch()).toBe(false);
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
it('Should be able to launch another job after staking more tokens', async () => {
|
|
422
|
-
await job.initialize();
|
|
423
|
-
await job.stake(1);
|
|
424
|
-
|
|
425
|
-
expect(await job.launch()).toBe(true);
|
|
426
|
-
expect(await job.status()).toBe(EscrowStatus.Launched);
|
|
427
|
-
|
|
428
|
-
expect(await job.allocate(1)).toBe(true);
|
|
429
|
-
|
|
430
|
-
const newJob = new Job({
|
|
431
|
-
gasPayer: DEFAULT_GAS_PAYER_PRIVKEY,
|
|
432
|
-
reputationOracle: REPUTATION_ORACLE_PRIVKEY,
|
|
433
|
-
manifest: manifest,
|
|
434
|
-
hmTokenAddr: DEFAULT_HMTOKEN_ADDR,
|
|
435
|
-
stakingAddr: DEFAULT_STAKING_ADDR,
|
|
436
|
-
logLevel: 'error',
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
await newJob.initialize();
|
|
440
|
-
await newJob.stake(1);
|
|
441
|
-
expect(await newJob.launch()).toBe(true);
|
|
442
|
-
});
|
|
443
384
|
});
|
|
444
385
|
|
|
445
386
|
describe('Access existing job from trusted handler', () => {
|
|
@@ -451,14 +392,12 @@ describe('Test Job', () => {
|
|
|
451
392
|
reputationOracle: REPUTATION_ORACLE_PRIVKEY,
|
|
452
393
|
manifest: manifest,
|
|
453
394
|
hmTokenAddr: DEFAULT_HMTOKEN_ADDR,
|
|
454
|
-
stakingAddr: DEFAULT_STAKING_ADDR,
|
|
455
395
|
trustedHandlers: [TRUSTED_OPERATOR1_PRIVKEY],
|
|
456
396
|
logLevel: 'error',
|
|
457
397
|
});
|
|
458
398
|
|
|
459
399
|
await originalJob.initialize();
|
|
460
400
|
await originalJob.launch();
|
|
461
|
-
await originalJob.stake(1);
|
|
462
401
|
await originalJob.setup();
|
|
463
402
|
|
|
464
403
|
job = new Job({
|
|
@@ -468,7 +407,7 @@ describe('Test Job', () => {
|
|
|
468
407
|
escrowAddr: originalJob.contractData?.escrowAddr,
|
|
469
408
|
factoryAddr: originalJob.contractData?.factoryAddr,
|
|
470
409
|
trustedHandlers: [TRUSTED_OPERATOR1_PRIVKEY],
|
|
471
|
-
logLevel: '
|
|
410
|
+
logLevel: 'debug',
|
|
472
411
|
});
|
|
473
412
|
});
|
|
474
413
|
|
|
@@ -477,7 +416,8 @@ describe('Test Job', () => {
|
|
|
477
416
|
});
|
|
478
417
|
|
|
479
418
|
it('Should be able to initializes the job by accessing existing escrow', async () => {
|
|
480
|
-
|
|
419
|
+
const initialized = await job.initialize();
|
|
420
|
+
expect(initialized).toBe(true);
|
|
481
421
|
|
|
482
422
|
expect(await job.manifestData?.manifestlink?.url).toBe('uploaded-key');
|
|
483
423
|
expect(await job.manifestData?.manifestlink?.hash).toBe('uploaded-hash');
|
|
@@ -490,7 +430,7 @@ describe('Test Job', () => {
|
|
|
490
430
|
expect(await job.status()).toBe(EscrowStatus.Pending);
|
|
491
431
|
});
|
|
492
432
|
|
|
493
|
-
it('Should
|
|
433
|
+
it('Should be able to setup the job again', async () => {
|
|
494
434
|
await job.initialize();
|
|
495
435
|
|
|
496
436
|
expect(await job.setup()).toBe(false);
|
|
@@ -504,6 +444,7 @@ describe('Test Job', () => {
|
|
|
504
444
|
|
|
505
445
|
it('Should be able to add trusted handlers', async () => {
|
|
506
446
|
await job.initialize();
|
|
447
|
+
await job.launch();
|
|
507
448
|
|
|
508
449
|
expect(await job.isTrustedHandler(DEFAULT_GAS_PAYER_ADDR)).toBe(true);
|
|
509
450
|
|
|
@@ -520,6 +461,8 @@ describe('Test Job', () => {
|
|
|
520
461
|
|
|
521
462
|
it('Should be able to bulk payout workers', async () => {
|
|
522
463
|
await job.initialize();
|
|
464
|
+
await job.launch();
|
|
465
|
+
await job.setup();
|
|
523
466
|
|
|
524
467
|
expect(
|
|
525
468
|
await job.bulkPayout(
|
|
@@ -574,6 +517,8 @@ describe('Test Job', () => {
|
|
|
574
517
|
|
|
575
518
|
it('Should encrypt result, when bulk paying out workers', async () => {
|
|
576
519
|
await job.initialize();
|
|
520
|
+
await job.launch();
|
|
521
|
+
await job.setup();
|
|
577
522
|
|
|
578
523
|
jest.clearAllMocks();
|
|
579
524
|
const finalResults = { results: 0 };
|
|
@@ -600,6 +545,8 @@ describe('Test Job', () => {
|
|
|
600
545
|
|
|
601
546
|
it('Should not encrypt result, when bulk paying out workers', async () => {
|
|
602
547
|
await job.initialize();
|
|
548
|
+
await job.launch();
|
|
549
|
+
await job.setup();
|
|
603
550
|
|
|
604
551
|
jest.clearAllMocks();
|
|
605
552
|
const finalResults = { results: 0 };
|
|
@@ -626,6 +573,8 @@ describe('Test Job', () => {
|
|
|
626
573
|
|
|
627
574
|
it('Should store result in private storage, when bulk paying out workers', async () => {
|
|
628
575
|
await job.initialize();
|
|
576
|
+
await job.launch();
|
|
577
|
+
await job.setup();
|
|
629
578
|
|
|
630
579
|
jest.clearAllMocks();
|
|
631
580
|
const finalResults = { results: 0 };
|
|
@@ -653,6 +602,8 @@ describe('Test Job', () => {
|
|
|
653
602
|
|
|
654
603
|
it('Should store result in public storage, when bulk paying out workers', async () => {
|
|
655
604
|
await job.initialize();
|
|
605
|
+
await job.launch();
|
|
606
|
+
await job.setup();
|
|
656
607
|
|
|
657
608
|
jest.clearAllMocks();
|
|
658
609
|
const finalResults = { results: 0 };
|
|
@@ -681,6 +632,8 @@ describe('Test Job', () => {
|
|
|
681
632
|
|
|
682
633
|
it('Should return final result', async () => {
|
|
683
634
|
await job.initialize();
|
|
635
|
+
await job.launch();
|
|
636
|
+
await job.setup();
|
|
684
637
|
|
|
685
638
|
const finalResults = { results: 0 };
|
|
686
639
|
await job.bulkPayout(
|
|
@@ -701,12 +654,16 @@ describe('Test Job', () => {
|
|
|
701
654
|
|
|
702
655
|
it('Should be able to abort the job', async () => {
|
|
703
656
|
await job.initialize();
|
|
657
|
+
await job.launch();
|
|
658
|
+
await job.setup();
|
|
704
659
|
|
|
705
660
|
expect(await job.abort()).toBe(true);
|
|
706
661
|
});
|
|
707
662
|
|
|
708
663
|
it('Should be able to abort partially paid job', async () => {
|
|
709
664
|
await job.initialize();
|
|
665
|
+
await job.launch();
|
|
666
|
+
await job.setup();
|
|
710
667
|
|
|
711
668
|
const finalResults = { results: 0 };
|
|
712
669
|
await job.bulkPayout(
|
|
@@ -725,6 +682,8 @@ describe('Test Job', () => {
|
|
|
725
682
|
|
|
726
683
|
it('Should not be able to abort fully paid job', async () => {
|
|
727
684
|
await job.initialize();
|
|
685
|
+
await job.launch();
|
|
686
|
+
await job.setup();
|
|
728
687
|
|
|
729
688
|
const finalResults = { results: 0 };
|
|
730
689
|
await job.bulkPayout(
|
|
@@ -743,6 +702,8 @@ describe('Test Job', () => {
|
|
|
743
702
|
|
|
744
703
|
it('Should be able to cancel the job', async () => {
|
|
745
704
|
await job.initialize();
|
|
705
|
+
await job.launch();
|
|
706
|
+
await job.setup();
|
|
746
707
|
|
|
747
708
|
expect(await job.cancel()).toBe(true);
|
|
748
709
|
expect((await job.balance())?.toString()).toBe(toFullDigit(0).toString());
|
|
@@ -750,6 +711,8 @@ describe('Test Job', () => {
|
|
|
750
711
|
|
|
751
712
|
it('Should be able to cancel partially paid job', async () => {
|
|
752
713
|
await job.initialize();
|
|
714
|
+
await job.launch();
|
|
715
|
+
await job.setup();
|
|
753
716
|
|
|
754
717
|
const finalResults = { results: 0 };
|
|
755
718
|
await job.bulkPayout(
|
|
@@ -769,6 +732,8 @@ describe('Test Job', () => {
|
|
|
769
732
|
|
|
770
733
|
it('Should not be able to cancel paid job', async () => {
|
|
771
734
|
await job.initialize();
|
|
735
|
+
await job.launch();
|
|
736
|
+
await job.setup();
|
|
772
737
|
|
|
773
738
|
const finalResults = { results: 0 };
|
|
774
739
|
await job.bulkPayout(
|
|
@@ -784,34 +749,5 @@ describe('Test Job', () => {
|
|
|
784
749
|
|
|
785
750
|
expect(await job.cancel()).toBe(false);
|
|
786
751
|
});
|
|
787
|
-
|
|
788
|
-
it('Should not be able to allocate to job without staking', async () => {
|
|
789
|
-
await job.initialize();
|
|
790
|
-
expect(await job.allocate(1, TRUSTED_OPERATOR1_ADDR)).toBe(false);
|
|
791
|
-
});
|
|
792
|
-
|
|
793
|
-
it('Should be able to allocate to job after staking', async () => {
|
|
794
|
-
await job.initialize();
|
|
795
|
-
await job.stake(1, TRUSTED_OPERATOR1_ADDR);
|
|
796
|
-
|
|
797
|
-
expect(await job.allocate(1, TRUSTED_OPERATOR1_ADDR)).toBe(true);
|
|
798
|
-
});
|
|
799
|
-
|
|
800
|
-
it('Should be able to launch another job after staking', async () => {
|
|
801
|
-
await job.initialize();
|
|
802
|
-
await job.stake(1, TRUSTED_OPERATOR1_ADDR);
|
|
803
|
-
|
|
804
|
-
const newJob = new Job({
|
|
805
|
-
gasPayer: TRUSTED_OPERATOR1_PRIVKEY,
|
|
806
|
-
reputationOracle: REPUTATION_ORACLE_PRIVKEY,
|
|
807
|
-
manifest: manifest,
|
|
808
|
-
hmTokenAddr: DEFAULT_HMTOKEN_ADDR,
|
|
809
|
-
stakingAddr: DEFAULT_STAKING_ADDR,
|
|
810
|
-
logLevel: 'error',
|
|
811
|
-
});
|
|
812
|
-
|
|
813
|
-
await newJob.initialize();
|
|
814
|
-
expect(await newJob.launch()).toBe(true);
|
|
815
|
-
});
|
|
816
752
|
});
|
|
817
753
|
});
|
package/test/utils/constants.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
export const DEFAULT_HMTOKEN_ADDR =
|
|
2
2
|
'0x5FbDB2315678afecb367f032d93F642f64180aa3';
|
|
3
3
|
|
|
4
|
-
export const DEFAULT_STAKING_ADDR =
|
|
5
|
-
'0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512';
|
|
6
|
-
|
|
7
4
|
export const DEFAULT_GAS_PAYER_ADDR =
|
|
8
5
|
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
|
|
9
6
|
export const DEFAULT_GAS_PAYER_PRIVKEY =
|