-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlibraryMockHelper.ts
More file actions
162 lines (135 loc) · 5.3 KB
/
libraryMockHelper.ts
File metadata and controls
162 lines (135 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { Address } from 'set-protocol-utils';
import * as _ from 'lodash';
import {
AddressArrayUtilsMockContract,
BoundsLibraryMockContract,
Bytes32LibraryMockContract,
CommonValidationsLibraryMockContract,
CommonMathMockContract,
CompoundUtilsMockContract,
HashUtilsMockContract,
ScaleValidationsMockContract
} from '../contracts';
import { BigNumber } from 'bignumber.js';
import {
getContractInstance,
linkLibrariesToDeploy,
importArtifactsFromSource,
txnFrom
} from '../web3Helper';
import { ZERO } from '../constants';
const AddressArrayUtilsMock = importArtifactsFromSource('AddressArrayUtilsMock');
const BoundsLibraryMock = importArtifactsFromSource('BoundsLibraryMock');
const Bytes32Library = importArtifactsFromSource('Bytes32Library');
const Bytes32LibraryMock = importArtifactsFromSource('Bytes32LibraryMock');
const CommonMathMock = importArtifactsFromSource('CommonMathMock');
const CommonValidationsLibrary = importArtifactsFromSource('CommonValidationsLibrary');
const CommonValidationsLibraryMock = importArtifactsFromSource('CommonValidationsLibraryMock');
const CompoundUtilsMock = importArtifactsFromSource('CompoundUtilsMock');
const HashUtilsMock = importArtifactsFromSource('HashUtilsMock');
const ScaleValidationsMock = importArtifactsFromSource('ScaleValidationsMock');
export class LibraryMockHelper {
private _contractOwnerAddress: Address;
constructor(contractOwnerAddress: Address) {
this._contractOwnerAddress = contractOwnerAddress;
}
/* ============ Deployment ============ */
public async deployAddressArrayUtilsMockAsync(
from: Address = this._contractOwnerAddress
): Promise<AddressArrayUtilsMockContract> {
const addressArrayUtils = await AddressArrayUtilsMock.new(txnFrom(from));
return new AddressArrayUtilsMockContract(
getContractInstance(addressArrayUtils),
txnFrom(from),
);
}
public async deployCommonValidationsLibraryAsync(
from: Address = this._contractOwnerAddress
): Promise<CommonValidationsLibraryMockContract> {
await linkLibrariesToDeploy(CommonValidationsLibraryMock, [CommonValidationsLibrary], this._contractOwnerAddress);
const commonValidationsMockContract = await CommonValidationsLibraryMock.new(txnFrom(from));
return new CommonValidationsLibraryMockContract(
getContractInstance(commonValidationsMockContract),
txnFrom(from),
);
}
public async deployBytes32LibraryAsync(
from: Address = this._contractOwnerAddress
): Promise<Bytes32LibraryMockContract> {
await linkLibrariesToDeploy(Bytes32LibraryMock, [Bytes32Library], this._contractOwnerAddress);
const bytes32MockContract = await Bytes32LibraryMock.new(txnFrom(from));
return new Bytes32LibraryMockContract(getContractInstance(bytes32MockContract), txnFrom(from));
}
public async deployCommonMathLibraryAsync(
from: Address = this._contractOwnerAddress
): Promise<CommonMathMockContract> {
const truffleCommonMathLibrary = await CommonMathMock.new(txnFrom(from));
return new CommonMathMockContract(
getContractInstance(truffleCommonMathLibrary),
txnFrom(from),
);
}
public async deployCompoundUtilsLibraryMockAsync(
from: Address = this._contractOwnerAddress
): Promise<CompoundUtilsMockContract> {
const compoundUtilsMockContract = await CompoundUtilsMock.new(txnFrom(from));
return new CompoundUtilsMockContract(getContractInstance(compoundUtilsMockContract), txnFrom(from));
}
public async deployScaleValidationsMockAsync(
from: Address = this._contractOwnerAddress
): Promise<ScaleValidationsMockContract> {
const scaleValidationsMockContract = await ScaleValidationsMock.new(txnFrom(from));
return new ScaleValidationsMockContract(getContractInstance(scaleValidationsMockContract), txnFrom(from));
}
public async deployHashUtilsMockAsync(
from: Address = this._contractOwnerAddress
): Promise<HashUtilsMockContract> {
const hashUtilsMockContract = await HashUtilsMock.new(txnFrom(from));
return new HashUtilsMockContract(getContractInstance(hashUtilsMockContract), txnFrom(from));
}
public async deployBoundsLibraryMockAsync(
minBound: BigNumber,
maxBound: BigNumber,
from: Address = this._contractOwnerAddress
): Promise<BoundsLibraryMockContract> {
const boundsLibraryMockContract = await BoundsLibraryMock.new(minBound, maxBound, txnFrom(from));
return new BoundsLibraryMockContract(getContractInstance(boundsLibraryMockContract), txnFrom(from));
}
public ceilLog10(
value: BigNumber
): BigNumber {
const valueNum = value.toNumber();
if (valueNum == 1) return ZERO;
let x = valueNum - 1;
let result = 0;
if (x >= 10000000000000000000000000000000000000000000000000000000000000000) {
x /= 10000000000000000000000000000000000000000000000000000000000000000;
result += 64;
}
if (x >= 100000000000000000000000000000000) {
x /= 100000000000000000000000000000000;
result += 32;
}
if (x >= 10000000000000000) {
x /= 10000000000000000;
result += 16;
}
if (x >= 100000000) {
x /= 100000000;
result += 8;
}
if (x >= 10000) {
x /= 10000;
result += 4;
}
if (x >= 100) {
x /= 100;
result += 2;
}
if (x >= 10) {
x /= 10;
result += 1;
}
return new BigNumber(result + 1);
}
}