-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
96 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./DummyImplementation.sol"; | ||
import "../proxy/uups/UUPSProxiable.sol"; | ||
|
||
contract DummyImplementationProxiable is DummyImplementation, UUPSProxiable { | ||
function updateCodeAddress(address newImplementation) public { | ||
_updateCodeAddress(newImplementation); | ||
} | ||
} | ||
|
||
contract DummyImplementationV2Proxiable is DummyImplementationV2, UUPSProxiable { | ||
function updateCodeAddress(address newImplementation) public { | ||
_updateCodeAddress(newImplementation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const { expectRevert } = require('@openzeppelin/test-helpers'); | ||
const ethereumjsUtil = require('ethereumjs-util'); | ||
|
||
const shouldBehaveLikeProxy = require('../Proxy.behaviour'); | ||
|
||
const DummyImplementation = artifacts.require('DummyImplementation') | ||
const DummyImplementationProxiable = artifacts.require('DummyImplementationProxiable') | ||
const DummyImplementationV2Proxiable = artifacts.require('DummyImplementationV2Proxiable') | ||
const UUPSProxy = artifacts.require('UUPSProxy'); | ||
|
||
const UUPS_UUID = '0xc5f16f0fcc639fa48a6947836d9850f504798523bf8c9a3a87d5876cf622bcf7'; | ||
|
||
function toChecksumAddress (address) { | ||
return ethereumjsUtil.toChecksumAddress('0x' + address.replace(/^0x/, '').padStart(40, '0')); | ||
} | ||
|
||
contract('UUPSProxy', function (accounts) { | ||
const [ proxyCreator ] = accounts; | ||
|
||
const createProxy = async function (implementation, _admin, initData, opts) { | ||
return UUPSProxy.new(implementation, initData, opts); | ||
}; | ||
|
||
shouldBehaveLikeProxy(createProxy, undefined, proxyCreator, { | ||
artefact: DummyImplementationProxiable, | ||
slot: UUPS_UUID, | ||
}); | ||
|
||
context('UUPS', function () { | ||
beforeEach(async function () { | ||
this.implementation = await DummyImplementation.new(); | ||
this.implementationproxiable = await DummyImplementationProxiable.new(); | ||
this.implementationproxiablev2 = await DummyImplementationV2Proxiable.new(); | ||
const { address } = await createProxy(this.implementationproxiable.address, undefined, '0x', { from: proxyCreator }); | ||
this.dummy = new DummyImplementationProxiable(address); | ||
}); | ||
|
||
it('check uuid', async function() { | ||
expect(await this.dummy.proxiableUUID()).to.be.equal(UUPS_UUID); | ||
}); | ||
|
||
it('can update to proxiable', async function() { | ||
await this.dummy.updateCodeAddress(this.implementationproxiablev2.address); | ||
const implementation = toChecksumAddress((await web3.eth.getStorageAt(this.dummy.address, UUPS_UUID)).substr(-40)); | ||
expect(implementation).to.be.equal(this.implementationproxiablev2.address); | ||
}); | ||
|
||
it('does not deploy with non-proxiable', async function() { | ||
await expectRevert.unspecified(createProxy(this.implementation.address, undefined, '0x', { from: proxyCreator })); | ||
}); | ||
|
||
it('does not update to non-proxiable', async function() { | ||
await expectRevert.unspecified(this.dummy.updateCodeAddress(this.implementation.address)); | ||
}); | ||
}); | ||
}); |