From: Sdk testing getting Invalid number of parameters - #2 by CIX
I understand this as you wanting to test an upgraded version of the contract.
To do this, you want to combine https://docs.openzeppelin.com/sdk/2.5/testing and
https://docs.openzeppelin.com/sdk/2.5/zos-lib
I have created some sample code based on the documentation above showing a version 0 and a version 1 of the contract and associated tests including upgrading from version 0 to version 1.
Let me know if you need more information.
Sample_v0.sol
pragma solidity ^0.5.0;
contract Sample_v0 {
function greet() public pure returns (string memory) {
return "A sample";
}
}
Sample_v1.sol
pragma solidity ^0.5.0;
contract Sample_v1 {
function greet() public pure returns (string memory) {
return "An upgraded sample";
}
}
Sample_v0.test.js
const { TestHelper } = require('@openzeppelin/cli');
const { Contracts, ZWeb3 } = require('@openzeppelin/upgrades');
ZWeb3.initialize(web3.currentProvider);
const Sample = Contracts.getFromLocal('Sample_v0');
require('chai').should();
contract('Sample_v0', function () {
beforeEach(async function () {
this.project = await TestHelper();
})
it('should create a proxy', async function () {
const proxy = await this.project.createProxy(Sample);
const result = await proxy.methods.greet().call();
result.should.eq('A sample');
})
})
Sample_v1.test.js
const { TestHelper } = require('@openzeppelin/cli');
const { Contracts, ZWeb3 } = require('@openzeppelin/upgrades');
ZWeb3.initialize(web3.currentProvider);
const Sample_v0 = Contracts.getFromLocal('Sample_v0');
const Sample_v1 = Contracts.getFromLocal('Sample_v1');
require('chai').should();
contract('Sample_v1', function () {
beforeEach(async function () {
this.project = await TestHelper();
})
it('should create a proxy', async function () {
const proxy = await this.project.createProxy(Sample_v0);
const result_v0 = await proxy.methods.greet().call();
result_v0.should.eq('A sample');
await this.project.upgradeProxy(proxy.address, Sample_v1);
const result_v1 = await proxy.methods.greet().call();
result_v1.should.eq('An upgraded sample');
})
})