Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: split deploy tests in integration and runtime #1344

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions packages/deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,20 @@ where:
We assume that the imported contracts are well tested in their own package by
having enough unit tests and more that 80% coverage. This repo contains
integrations tests, tests for the deployment process and tests that verify the
integrity of the system. For example in the case of the `SignedMultiGiveaway`
contract we check the roles and the users assigned to them are correctly
configured.
runtime integrity of the system. For example in the case of the
`SignedMultiGiveaway` contract we check the roles and the users assigned to them
are correctly configured.

There are three directories to distinguish the type of test:

- runtime_test: tests that check the runtime consistency of the contracts. They
must be able to run on a live network, a forked network or after a local
deploy.
- integration_test: tests used to check some functionality of imported contract
when they interact together. They are meant to be run in a forked network or
on a local deploy, they don't necessarily work on a live network.
- test: tests in this folder are always executed they must run at least on a
local deploy.

To test the deployment process:

Expand All @@ -61,7 +72,7 @@ To test the deployment process:
`fork:deploy NETWORK` where NETWORK is `mainnet`,`polygon` ,`goerli`,`mumbai`,
etc.

The tests the integrity of the system:
To test the integrity of the system:

- using hardhat local node and `hardhat-deploy` deployment scripts: `yarn test`
- on a live network over contracts that are already deployed:
Expand Down
30 changes: 30 additions & 0 deletions packages/deploy/deploy/000_core/001_deploy_polygon_land.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {deployments, getNamedAccounts} = hre;
const {deploy} = deployments;

const {deployer, upgradeAdmin} = await getNamedAccounts();

const TRUSTED_FORWARDER_V2 = await deployments.get('TRUSTED_FORWARDER_V2');

await deploy('PolygonLand', {
from: deployer,
contract:
'@sandbox-smart-contracts/core/src/solc_0.8/polygon/child/land/PolygonLandV2.sol:PolygonLandV2',
proxy: {
owner: upgradeAdmin,
proxyContract: 'OpenZeppelinTransparentProxy',
execute: {
methodName: 'initialize',
args: [TRUSTED_FORWARDER_V2.address],
},
upgradeIndex: 0,
},
log: true,
});
};
export default func;
func.tags = ['PolygonLand', 'PolygonLand_deploy', 'L2'];
func.dependencies = ['TRUSTED_FORWARDER_V2'];
28 changes: 28 additions & 0 deletions packages/deploy/deploy/000_core/002_setup_polygon_land.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {DeployFunction} from 'hardhat-deploy/types';
import {HardhatRuntimeEnvironment} from 'hardhat/types';

export const royaltyAmount = 500;

const func: DeployFunction = async function (
hre: HardhatRuntimeEnvironment
): Promise<void> {
const {deployments, getNamedAccounts} = hre;
const {execute, read, catchUnknownSigner} = deployments;

const {sandAdmin} = await getNamedAccounts();
const currentAdmin = await read('PolygonLand', {}, 'getAdmin');
if (currentAdmin !== sandAdmin) {
await catchUnknownSigner(
execute(
'PolygonLand',
{from: currentAdmin, log: true},
'changeAdmin',
sandAdmin
)
);
}
};

export default func;
func.tags = ['PolygonLand', 'PolygonLand_setup', 'L2'];
func.dependencies = ['PolygonLand_deploy'];
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const {deployer, assetAdmin} = await getNamedAccounts();
await deploy('AuthSuperValidator', {
from: deployer,
contract: 'AuthSuperValidator',
contract:
'@sandbox-smart-contracts/asset/contracts/AuthSuperValidator.sol:AuthSuperValidator',
args: [assetAdmin],
log: true,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ func.tags = ['Exchange', 'Exchange_deploy'];
func.dependencies = [
'RoyaltiesRegistry_deploy',
'OrderValidator_deploy',
'OrderValidator_setup',
'TRUSTED_FORWARDER_V2',
];
2 changes: 2 additions & 0 deletions packages/deploy/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
addNodeAndMnemonic,
skipDeploymentsOnLiveNetworks,
} from './utils/hardhatConfig';
import './tasks/specialTests';
import './tasks/importedPackages';

// Package name : solidity source code path
Expand All @@ -23,6 +24,7 @@ const importedPackages = {
'@sandbox-smart-contracts/dependency-operator-filter': 'contracts/',
'@sandbox-smart-contracts/dependency-royalty-management': 'contracts/',
'@sandbox-smart-contracts/core': [
'/src/solc_0.8/polygon/child/land/PolygonLandV2.sol',
'/src/solc_0.8/polygon/child/sand/PolygonSand.sol',
'/src/solc_0.8/test/FakeChildChainManager.sol',
],
Expand Down
131 changes: 131 additions & 0 deletions packages/deploy/integration_test/marketplaceLand/exchange.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import {getContract, withSnapshot} from '../../utils/testUtils';
import {expect} from 'chai';
import {ethers} from 'hardhat';
import {BigNumber} from 'ethers';
import {AssetERC20, AssetERC721, OrderDefault, signOrder} from './orders';

const setupTest = withSnapshot(
['Exchange', 'PolygonSand', 'PolygonLand'],
async (hre) => {
const {sandAdmin} = await hre.getNamedAccounts();
const [user1, user2, minter] = await hre.getUnnamedAccounts();

const sandContract = await getContract(hre, 'PolygonSand');

const sandAdminSigner = await ethers.getSigner(sandAdmin);
const landContract = await getContract(hre, 'PolygonLand', sandAdminSigner);
await landContract.setMinter(minter, true);
const landContractAsMinter = await landContract.connect(
await ethers.getSigner(minter)
);

const childChainManager = await getContract(
hre,
'CHILD_CHAIN_MANAGER',
sandAdminSigner
);
await childChainManager.setPolygonAsset(landContract.address);

const exchangeAsUser2 = await getContract(
hre,
'Exchange',
await ethers.getSigner(user2)
);
const orderValidatorAsAdmin = await getContract(
hre,
'OrderValidator',
await ethers.getSigner(sandAdmin)
);
const TSB_ROLE = await orderValidatorAsAdmin.TSB_ROLE();
// enable land in whitelist
await orderValidatorAsAdmin.grantRole(
TSB_ROLE,
landContractAsMinter.address
);
return {
landContract,
landContractAsMinter,
sandContract,
exchangeAsUser2,
orderValidatorAsAdmin,
sandAdmin,
user1,
user2,
minter,
mintSand: async (user: string, amount: BigNumber) =>
childChainManager.callSandDeposit(
sandContract.address,
user,
ethers.utils.defaultAbiCoder.encode(['uint256'], [amount])
),
};
}
);

describe('Marketplace Land <-> Sand exchange', function () {
it('simple exchange', async function () {
const {
sandContract,
landContractAsMinter,
exchangeAsUser2,
orderValidatorAsAdmin,
user1,
user2,
mintSand,
} = await setupTest();
const oneEth = ethers.utils.parseEther('1');
const landTokenId = 0;
const size = 1;
await landContractAsMinter.mintQuad(user1, size, 0, 0, '0x');
expect(await landContractAsMinter.balanceOf(user1)).to.be.equal(
size * size
);

await mintSand(user2, oneEth);
expect(await sandContract.balanceOf(user2)).to.be.equal(oneEth);

await sandContract
.connect(await ethers.getSigner(user2))
.approve(exchangeAsUser2.address, oneEth);
await landContractAsMinter
.connect(await ethers.getSigner(user1))
.approve(exchangeAsUser2.address, landTokenId);

const makerAsset = await AssetERC721(landContractAsMinter, landTokenId);
const takerAsset = await AssetERC20(sandContract, oneEth);
const orderLeft = OrderDefault(
user1,
makerAsset,
ethers.constants.AddressZero,
takerAsset,
1,
0,
0
);
const orderRight = await OrderDefault(
user2,
takerAsset,
ethers.constants.AddressZero,
makerAsset,
1,
0,
0
);
const makerSig = await signOrder(orderLeft, user1, orderValidatorAsAdmin);
const takerSig = await signOrder(orderRight, user2, orderValidatorAsAdmin);
const tx = await exchangeAsUser2.matchOrders([
{
orderLeft,
signatureLeft: makerSig,
orderRight,
signatureRight: takerSig,
},
]);
const receipt = await tx.wait();
console.log(receipt.gasUsed.toString());
expect(await landContractAsMinter.balanceOf(user2)).to.be.equal(
size * size
);
expect(await sandContract.balanceOf(user1)).to.be.equal(oneEth);
});
});
Loading
Loading