Skip to content

Commit

Permalink
EntityManager Upgradeability Unit Test (#3740)
Browse files Browse the repository at this point in the history
  • Loading branch information
hareeshnagaraj authored Aug 26, 2022
1 parent 3b98f10 commit de178d2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
10 changes: 10 additions & 0 deletions contracts/contracts/test/TestEntityManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity ^0.5.0;

import "../EntityManager.sol";


contract TestEntityManager is EntityManager {
function newFunction() public pure returns (uint256) {
return 5;
}
}
1 change: 1 addition & 0 deletions contracts/test/_lib/artifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ export const TestStorage = artifacts.require('./contract/storage/test/TestStorag
export const TestContract = artifacts.require('./contract/test/TestContract')
export const TestContractWithStorage = artifacts.require('./contract/test/TestContractWithStorage')
export const TestUserReplicaSetManager = artifacts.require('./contract/test/TestUserReplicaSetManager')
export const TestEntityManager = artifacts.require('./contract/test/TestEntityManager')
34 changes: 33 additions & 1 deletion contracts/test/entityManager.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as _lib from './_lib/lib.js'
import {
EntityManager,
AdminUpgradeabilityProxy
AdminUpgradeabilityProxy,
TestEntityManager
} from './_lib/artifacts.js'

import * as _constants from './utils/constants'
Expand Down Expand Up @@ -114,4 +115,35 @@ contract('EntityManager', async (accounts) => {
)
})

it('EntityManager upgradeability validation', async () => {
// Attempt to reinitialize
await expectRevert(
entityManagerContract.initialize(verifierAddress, networkId),
'Contract instance has already been initialized.'
)
let deployUpgradedLogicContract = await TestEntityManager.new({ from: deployer })
let proxyInstance = await AdminUpgradeabilityProxy.at(entityManagerContract.address)
const upgradedLogicAddress = deployUpgradedLogicContract.address
// Attempt to upgrade from an invalid address (the initial deployer)
await expectRevert(
proxyInstance.upgradeTo(upgradedLogicAddress, { from: deployer }),
'revert'
)
// Perform upgrade from known admin
await proxyInstance.upgradeTo(upgradedLogicAddress, { from: proxyAdminAddress })
let testEntityManager = await TestEntityManager.at(entityManagerContract.address)
let newFunctionReturnValue = await testEntityManager.newFunction()
assert.isTrue(newFunctionReturnValue.eq(toBN(5)), "New function returned unexpected value")
// Confirm existing functionality
let verifyTx = await testEntityManager.manageIsVerified(1, true, { from: verifierAddress })
await expectEvent.inTransaction(
verifyTx.tx,
EntityManager,
'ManageIsVerified',
{
_userId: toBN(1),
_isVerified: true
}
)
})
})

0 comments on commit de178d2

Please sign in to comment.