forked from aave/aave-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupgradeability.spec.ts
130 lines (103 loc) · 4.52 KB
/
upgradeability.spec.ts
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
import {ITestEnv, ContractsInstancesOrigin, ITokenInstances, ContractId} from "../utils/types"
import {
LendingPoolCoreInstance,
LendingPoolConfiguratorInstance,
LendingPoolAddressesProviderInstance,
LendingPoolDataProviderInstance,
LendingPoolInstance,
MockLendingPoolCoreContract,
MockLendingPoolCoreInstance,
} from "../utils/typechain-types/truffle-contracts"
import {testEnvProvider} from "../utils/truffle/dlp-tests-env"
import {RAY, ETHEREUM_ADDRESS} from "../utils/constants"
import {getTruffleContract, getTruffleContractInstance} from "../utils/truffle/truffle-core-utils"
import BN = require("bn.js")
import { TransactionReceipt } from "web3/types"
const {expectEvent, expectRevert} = require("@openzeppelin/test-helpers")
const {expect} = require("chai")
contract("Upgradeability", async ([deployer, ...users]) => {
let _testEnvProvider: ITestEnv
let _configuratorInstance: LendingPoolConfiguratorInstance
let _coreInstance: LendingPoolCoreInstance
let _poolInstance: LendingPoolInstance
let _addressesProviderInstance: LendingPoolAddressesProviderInstance
let _dataProviderInstance: LendingPoolDataProviderInstance
let _mockCoreInstance: MockLendingPoolCoreInstance
before("Initializing test variables", async () => {
_testEnvProvider = await testEnvProvider(
artifacts,
[deployer, ...users],
ContractsInstancesOrigin.TruffleArtifacts,
)
const {
deployedInstances: {
lendingPoolConfiguratorInstance,
lendingPoolCoreInstance,
lendingPoolAddressesProviderInstance,
lendingPoolInstance,
lendingPoolDataProviderInstance,
},
getAllTokenInstances,
} = _testEnvProvider
_addressesProviderInstance = lendingPoolAddressesProviderInstance
_configuratorInstance = lendingPoolConfiguratorInstance
_coreInstance = lendingPoolCoreInstance
_dataProviderInstance = lendingPoolDataProviderInstance
_poolInstance = lendingPoolInstance
})
it("tries to call the initialization function on LendingPoolConfigurator", async () => {
await expectRevert(
_configuratorInstance.initialize(_addressesProviderInstance.address),
"Contract instance has already been initialized",
)
})
it("tries to call the initialization function on LendingPoolCore", async () => {
await expectRevert(
_coreInstance.initialize(_addressesProviderInstance.address),
"Contract instance has already been initialized",
)
})
it("tries to call the initialization function on LendingPool", async () => {
await expectRevert(
_poolInstance.initialize(_addressesProviderInstance.address),
"Contract instance has already been initialized",
)
})
it("tries to call the initialization function on DataProvider", async () => {
await expectRevert(
_dataProviderInstance.initialize(_addressesProviderInstance.address),
"Contract instance has already been initialized",
)
})
it("Deploys a new version of a LendingPoolCore contract", async () => {
const contract: any = await artifacts.require("MockLendingPoolCore")
const mathLibrary = await artifacts.require("WadRayMath")
const mathLibraryInstance = await mathLibrary.new()
const coreLibrary = await artifacts.require("CoreLibrary")
await coreLibrary.link("WadRayMath", mathLibraryInstance.address)
await contract.link("CoreLibrary", coreLibrary.address)
await contract.link("WadRayMath", mathLibraryInstance.address)
_mockCoreInstance = await contract.new()
const txResult = await _addressesProviderInstance.setLendingPoolCoreImpl(
_mockCoreInstance.address,
)
expectEvent(txResult, "LendingPoolCoreUpdated", {
newAddress: _mockCoreInstance.address,
})
})
it("Tries to execute initialize() on the newly deployed core", async () => {
const coreProxyAddress = await _addressesProviderInstance.getLendingPoolCore();
const instance : LendingPoolCoreInstance= await getTruffleContractInstance(artifacts, ContractId.LendingPoolCore, coreProxyAddress)
await expectRevert(
instance.initialize(_addressesProviderInstance.address),
"Contract instance has already been initialized",
)
})
it("Tries to deposit", async () => {
const coreProxyAddress = await _addressesProviderInstance.getLendingPoolCore();
const txReceipt : Truffle.TransactionResponse = await _poolInstance.deposit(ETHEREUM_ADDRESS, "100", "0", {value: "100"})
expectEvent.inTransaction(txReceipt.tx, coreProxyAddress, "ReserveUpdatedFromMock",{
revision: new BN(2)
})
})
})