Update docs
This commit is contained in:
@ -6,6 +6,7 @@ const ImplV1 = artifacts.require('DummyImplementation');
|
||||
const ImplV2 = artifacts.require('DummyImplementationV2');
|
||||
const ProxyAdmin = artifacts.require('ProxyAdmin');
|
||||
const TransparentUpgradeableProxy = artifacts.require('TransparentUpgradeableProxy');
|
||||
const ITransparentUpgradeableProxy = artifacts.require('ITransparentUpgradeableProxy');
|
||||
|
||||
contract('ProxyAdmin', function (accounts) {
|
||||
const [proxyAdminOwner, newAdmin, anotherAccount] = accounts;
|
||||
@ -18,12 +19,13 @@ contract('ProxyAdmin', function (accounts) {
|
||||
beforeEach(async function () {
|
||||
const initializeData = Buffer.from('');
|
||||
this.proxyAdmin = await ProxyAdmin.new({ from: proxyAdminOwner });
|
||||
this.proxy = await TransparentUpgradeableProxy.new(
|
||||
const proxy = await TransparentUpgradeableProxy.new(
|
||||
this.implementationV1.address,
|
||||
this.proxyAdmin.address,
|
||||
initializeData,
|
||||
{ from: proxyAdminOwner },
|
||||
);
|
||||
this.proxy = await ITransparentUpgradeableProxy.at(proxy.address);
|
||||
});
|
||||
|
||||
it('has an owner', async function () {
|
||||
|
||||
@ -34,7 +34,7 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro
|
||||
|
||||
describe('implementation', function () {
|
||||
it('returns the current implementation address', async function () {
|
||||
const implementation = await this.proxy.implementation.call({ from: proxyAdminAddress });
|
||||
const implementation = await this.proxy.implementation({ from: proxyAdminAddress });
|
||||
|
||||
expect(implementation).to.be.equal(this.implementationV0);
|
||||
});
|
||||
@ -55,7 +55,7 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro
|
||||
it('upgrades to the requested implementation', async function () {
|
||||
await this.proxy.upgradeTo(this.implementationV1, { from });
|
||||
|
||||
const implementation = await this.proxy.implementation.call({ from: proxyAdminAddress });
|
||||
const implementation = await this.proxy.implementation({ from: proxyAdminAddress });
|
||||
expect(implementation).to.be.equal(this.implementationV1);
|
||||
});
|
||||
|
||||
@ -108,7 +108,7 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro
|
||||
});
|
||||
|
||||
it('upgrades to the requested implementation', async function () {
|
||||
const implementation = await this.proxy.implementation.call({ from: proxyAdminAddress });
|
||||
const implementation = await this.proxy.implementation({ from: proxyAdminAddress });
|
||||
expect(implementation).to.be.equal(this.behavior.address);
|
||||
});
|
||||
|
||||
@ -173,7 +173,7 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro
|
||||
});
|
||||
|
||||
it('upgrades to the requested version and emits an event', async function () {
|
||||
const implementation = await this.proxy.implementation.call({ from: proxyAdminAddress });
|
||||
const implementation = await this.proxy.implementation({ from: proxyAdminAddress });
|
||||
expect(implementation).to.be.equal(this.behaviorV1.address);
|
||||
expectEvent(this.receipt, 'Upgraded', { implementation: this.behaviorV1.address });
|
||||
});
|
||||
@ -199,7 +199,7 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro
|
||||
});
|
||||
|
||||
it('upgrades to the requested version and emits an event', async function () {
|
||||
const implementation = await this.proxy.implementation.call({ from: proxyAdminAddress });
|
||||
const implementation = await this.proxy.implementation({ from: proxyAdminAddress });
|
||||
expect(implementation).to.be.equal(this.behaviorV2.address);
|
||||
expectEvent(this.receipt, 'Upgraded', { implementation: this.behaviorV2.address });
|
||||
});
|
||||
@ -228,7 +228,7 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro
|
||||
});
|
||||
|
||||
it('upgrades to the requested version and emits an event', async function () {
|
||||
const implementation = await this.proxy.implementation.call({ from: proxyAdminAddress });
|
||||
const implementation = await this.proxy.implementation({ from: proxyAdminAddress });
|
||||
expect(implementation).to.be.equal(this.behaviorV3.address);
|
||||
expectEvent(this.receipt, 'Upgraded', { implementation: this.behaviorV3.address });
|
||||
});
|
||||
@ -274,7 +274,7 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro
|
||||
});
|
||||
|
||||
it('assigns new proxy admin', async function () {
|
||||
const newProxyAdmin = await this.proxy.admin.call({ from: newAdmin });
|
||||
const newProxyAdmin = await this.proxy.admin({ from: newAdmin });
|
||||
expect(newProxyAdmin).to.be.equal(anotherAccount);
|
||||
});
|
||||
|
||||
@ -333,14 +333,23 @@ module.exports = function shouldBehaveLikeTransparentUpgradeableProxy (createPro
|
||||
);
|
||||
});
|
||||
|
||||
context('when function names clash', function () {
|
||||
describe('when function names clash', function () {
|
||||
it('when sender is proxy admin should run the proxy function', async function () {
|
||||
const value = await this.proxy.admin.call({ from: proxyAdminAddress });
|
||||
const value = await this.proxy.admin({ from: proxyAdminAddress, value: 0 });
|
||||
expect(value).to.be.equal(proxyAdminAddress);
|
||||
});
|
||||
|
||||
it('when sender is other should delegate to implementation', async function () {
|
||||
const value = await this.proxy.admin.call({ from: anotherAccount });
|
||||
const value = await this.proxy.admin({ from: anotherAccount, value: 0 });
|
||||
expect(value).to.be.equal('0x0000000000000000000000000000000011111142');
|
||||
});
|
||||
|
||||
it('when sender is proxy admin value should not be accepted', async function () {
|
||||
await expectRevert.unspecified(this.proxy.admin({ from: proxyAdminAddress, value: 1 }));
|
||||
});
|
||||
|
||||
it('when sender is other value should be accepted', async function () {
|
||||
const value = await this.proxy.admin({ from: anotherAccount, value: 1 });
|
||||
expect(value).to.be.equal('0x0000000000000000000000000000000011111142');
|
||||
});
|
||||
});
|
||||
|
||||
@ -2,12 +2,14 @@ const shouldBehaveLikeProxy = require('../Proxy.behaviour');
|
||||
const shouldBehaveLikeTransparentUpgradeableProxy = require('./TransparentUpgradeableProxy.behaviour');
|
||||
|
||||
const TransparentUpgradeableProxy = artifacts.require('TransparentUpgradeableProxy');
|
||||
const ITransparentUpgradeableProxy = artifacts.require('ITransparentUpgradeableProxy');
|
||||
|
||||
contract('TransparentUpgradeableProxy', function (accounts) {
|
||||
const [proxyAdminAddress, proxyAdminOwner] = accounts;
|
||||
|
||||
const createProxy = async function (logic, admin, initData, opts) {
|
||||
return TransparentUpgradeableProxy.new(logic, admin, initData, opts);
|
||||
const { address } = await TransparentUpgradeableProxy.new(logic, admin, initData, opts);
|
||||
return ITransparentUpgradeableProxy.at(address);
|
||||
};
|
||||
|
||||
shouldBehaveLikeProxy(createProxy, proxyAdminAddress, proxyAdminOwner);
|
||||
|
||||
Reference in New Issue
Block a user