Skip to content

Commit

Permalink
fix(pg): ChugSplash foundry library fails to compile when optimizer d…
Browse files Browse the repository at this point in the history
…isabled
  • Loading branch information
RPate97 committed Jun 26, 2023
1 parent fa3410c commit 1b0540c
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 85 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-tips-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chugsplash/plugins': patch
---

Fix compilation issue when optimizer disabled
10 changes: 8 additions & 2 deletions packages/plugins/chugsplash/Storage.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { ethers } from 'ethers'

import {
variables,
constructorArgs,
complexConstructorArgs,
immutableConstructorArgsOne,
immutableConstructorArgsTwo,
} from '../test/constants'

const projectName = 'My First Project'
Expand All @@ -24,9 +25,14 @@ const config: UserChugSplashConfig = {
MyStorage: {
contract: 'contracts/test/ContainsStorage.sol:Storage',
kind: 'proxy',
constructorArgs,
constructorArgs: immutableConstructorArgsOne,
variables,
},
MyOtherImmutables: {
contract: 'contracts/test/ContainsStorage.sol:OtherImmutables',
kind: 'proxy',
constructorArgs: immutableConstructorArgsTwo,
},
ComplexConstructorArgs: {
contract: 'ComplexConstructorArgs',
kind: 'immutable',
Expand Down
10 changes: 5 additions & 5 deletions packages/plugins/contracts/foundry/ChugSplash.sol
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ contract ChugSplash is Script {
function executeBatchActions(
BundledChugSplashAction[] memory actions,
IChugSplashManager manager,
uint maxGasLimit,
uint bufferedGasLimit,
DeployContractCost[] memory deployContractCosts
) private returns (DeploymentStatus) {
// Pull the deployment state from the contract to make sure we're up to date
Expand Down Expand Up @@ -364,7 +364,7 @@ contract ChugSplash is Script {
// Figure out the maximum number of actions that can be executed in a single batch
uint batchSize = utils.findMaxBatchSize(
utils.inefficientSlice(filteredActions, executed, filteredActions.length),
maxGasLimit,
bufferedGasLimit - ((bufferedGasLimit) * 20) / 100,
deployContractCosts
);
BundledChugSplashAction[] memory batch = utils.inefficientSlice(
Expand All @@ -377,7 +377,6 @@ contract ChugSplash is Script {
uint256[] memory _actionIndexes,
bytes32[][] memory _proofs
) = utils.disassembleActions(batch);
uint bufferedGasLimit = ((maxGasLimit) * 120) / 100;
manager.executeActions{ gas: bufferedGasLimit }(rawActions, _actionIndexes, _proofs);

// Return early if the deployment failed
Expand Down Expand Up @@ -408,11 +407,12 @@ contract ChugSplash is Script {
actionBundle
);

uint bufferedGasLimit = ((blockGasLimit / 2) * 120) / 100;
// Execute all the deploy contract actions and exit early if the deployment failed
DeploymentStatus status = executeBatchActions(
deployContractActions,
manager,
blockGasLimit / 2,
bufferedGasLimit,
deployContractCosts
);
if (status == DeploymentStatus.FAILED) {
Expand All @@ -436,7 +436,7 @@ contract ChugSplash is Script {
manager.initiateUpgrade{ gas: 1000000 }(targets, proofs);

// Execute all the set storage actions
executeBatchActions(setStorageActions, manager, blockGasLimit / 2, deployContractCosts);
executeBatchActions(setStorageActions, manager, bufferedGasLimit, deployContractCosts);

// Complete the upgrade
manager.finalizeUpgrade{ gas: 1000000 }(targets, proofs);
Expand Down
92 changes: 51 additions & 41 deletions packages/plugins/contracts/test/ContainsStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ pragma solidity ^0.8.9;

import { SimpleStorage } from "./SimpleStorage.sol";

contract Storage {
library Types {
enum TestEnum {
A,
B,
C
}

type UserDefinedType is uint256;
type UserDefinedBytes32 is bytes32;
type UserDefinedInt is int;
type UserDefinedInt8 is int8;
type UserDefinedUint8 is uint8;
type UserDefinedBool is bool;
}

enum TestEnum {
A,
B,
C
}
contract Storage {
struct SimpleStruct {
bytes32 a;
uint128 b;
Expand All @@ -24,7 +27,7 @@ contract Storage {
struct ComplexStruct {
int32 a;
mapping(uint32 => string) b;
UserDefinedType c;
Types.UserDefinedType c;
}

int public immutable immutableInt;
Expand All @@ -33,39 +36,21 @@ contract Storage {
uint8 public immutable immutableUint8;
bool public immutable immutableBool;
bytes32 public immutable immutableBytes32;
UserDefinedType public immutable immutableUserDefinedType;
uint public immutable immutableBigNumberUint;
int public immutable immutableBigNumberInt;
address public immutable immutableAddress;
Storage public immutable immutableContract;
TestEnum public immutable immutableEnum;

constructor(
int _immutableInt,
int8 _immutableInt8,
uint _immutableUint,
uint8 _immutableUint8,
bool _immutableBool,
bytes32 _immutableBytes32,
UserDefinedType _immutableUserDefinedType,
uint _immutableBigNumberUint,
int _immutableBigNumberInt,
address _immutableAddress,
Storage _immutableContract,
TestEnum _immutableEnum
bytes32 _immutableBytes32
) {
immutableInt = _immutableInt;
immutableInt8 = _immutableInt8;
immutableUint = _immutableUint;
immutableUint8 = _immutableUint8;
immutableBool = _immutableBool;
immutableBytes32 = _immutableBytes32;
immutableUserDefinedType = _immutableUserDefinedType;
immutableBigNumberUint = _immutableBigNumberUint;
immutableBigNumberInt = _immutableBigNumberInt;
immutableAddress = _immutableAddress;
immutableContract = _immutableContract;
immutableEnum = _immutableEnum;
}

function(uint256) internal pure returns (uint256) internalFunc;
Expand All @@ -85,21 +70,21 @@ contract Storage {
bytes32 public bytes32Test;
address public addressTest;
address payable public payableAddressTest;
UserDefinedType public userDefinedTypeTest;
UserDefinedBytes32 public userDefinedBytesTest;
UserDefinedInt public userDefinedInt;
UserDefinedInt8 public userDefinedInt8;
UserDefinedUint8 public userDefinedUint8;
UserDefinedBool public userDefinedBool;
UserDefinedInt public userDefinedBigNumberInt;
mapping(UserDefinedType => string) public userDefinedToStringMapping;
mapping(string => UserDefinedType) public stringToUserDefinedMapping;
UserDefinedType[2] public userDefinedFixedArray;
UserDefinedType[2][2] public userDefinedFixedNestedArray;
UserDefinedType[] public userDefinedDynamicArray;
Types.UserDefinedType public userDefinedTypeTest;
Types.UserDefinedBytes32 public userDefinedBytesTest;
Types.UserDefinedInt public userDefinedInt;
Types.UserDefinedInt8 public userDefinedInt8;
Types.UserDefinedUint8 public userDefinedUint8;
Types.UserDefinedBool public userDefinedBool;
Types.UserDefinedInt public userDefinedBigNumberInt;
mapping(Types.UserDefinedType => string) public userDefinedToStringMapping;
mapping(string => Types.UserDefinedType) public stringToUserDefinedMapping;
Types.UserDefinedType[2] public userDefinedFixedArray;
Types.UserDefinedType[2][2] public userDefinedFixedNestedArray;
Types.UserDefinedType[] public userDefinedDynamicArray;
Storage public contractTest;
TestEnum public enumTest;
TestEnum public bigNumberEnumTest;
Types.TestEnum public enumTest;
Types.TestEnum public bigNumberEnumTest;
SimpleStruct public simpleStruct;
ComplexStruct public complexStruct;
uint64[5] public uint64FixedArray;
Expand All @@ -124,7 +109,7 @@ contract Storage {
mapping(int128 => string) public int128ToStringMapping;
mapping(address => string) public addressToStringMapping;
mapping(SimpleStorage => string) public contractToStringMapping;
mapping(TestEnum => string) public enumToStringMapping;
mapping(Types.TestEnum => string) public enumToStringMapping;
mapping(bytes => string) public bytesToStringMapping;
mapping(string => mapping(string => string)) public nestedMapping;
mapping(uint8 => mapping(string => mapping(address => uint))) public multiNestedMapping;
Expand All @@ -133,3 +118,28 @@ contract Storage {
return complexStruct.b[_mappingKey];
}
}

contract OtherImmutables {
Types.UserDefinedType public immutable immutableUserDefinedType;
uint public immutable immutableBigNumberUint;
int public immutable immutableBigNumberInt;
address public immutable immutableAddress;
Storage public immutable immutableContract;
Types.TestEnum public immutable immutableEnum;

constructor(
Types.UserDefinedType _immutableUserDefinedType,
uint _immutableBigNumberUint,
int _immutableBigNumberInt,
address _immutableAddress,
Storage _immutableContract,
Types.TestEnum _immutableEnum
) {
immutableUserDefinedType = _immutableUserDefinedType;
immutableBigNumberUint = _immutableBigNumberUint;
immutableBigNumberInt = _immutableBigNumberInt;
immutableAddress = _immutableAddress;
immutableContract = _immutableContract;
immutableEnum = _immutableEnum;
}
}
50 changes: 33 additions & 17 deletions packages/plugins/test/Storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@ import { chugsplash } from 'hardhat'
import { expect } from 'chai'
import { BigNumber, Contract } from 'ethers'

import { complexConstructorArgs, constructorArgs, variables } from './constants'
import {
complexConstructorArgs,
immutableConstructorArgsOne,
immutableConstructorArgsTwo,
variables,
} from './constants'

describe('Storage', () => {
let MyStorage: Contract
let MyOtherImmutables: Contract
let MySimpleStorage: Contract
let Stateless: Contract
let ComplexConstructorArgs: Contract
before(async () => {
MyStorage = await chugsplash.getContract('My First Project', 'MyStorage')
MyOtherImmutables = await chugsplash.getContract(
'My First Project',
'MyOtherImmutables'
)
MySimpleStorage = await chugsplash.getContract(
'My First Project',
'MySimpleStorage'
Expand All @@ -34,67 +44,73 @@ describe('Storage', () => {

it('does set immutable int', async () => {
expect(await MyStorage.immutableInt()).to.deep.equals(
BigNumber.from(constructorArgs._immutableInt)
BigNumber.from(immutableConstructorArgsOne._immutableInt)
)
})

it('does set immutable int8', async () => {
expect(await MyStorage.immutableInt8()).equals(
constructorArgs._immutableInt8
immutableConstructorArgsOne._immutableInt8
)
})

it('does set immutable uint', async () => {
expect(await MyStorage.immutableUint()).to.deep.equals(
BigNumber.from(constructorArgs._immutableUint)
BigNumber.from(immutableConstructorArgsOne._immutableUint)
)
})

it('does set immutable uint8', async () => {
expect(await MyStorage.immutableUint8()).equals(
constructorArgs._immutableUint8
immutableConstructorArgsOne._immutableUint8
)
})

it('does set immutable bool', async () => {
expect(await MyStorage.immutableBool()).equals(
constructorArgs._immutableBool
immutableConstructorArgsOne._immutableBool
)
})

it('does set immutable bytes', async () => {
expect(await MyStorage.immutableBytes32()).equals(
constructorArgs._immutableBytes32
immutableConstructorArgsOne._immutableBytes32
)
})

it('does set immutable user defined type', async () => {
expect(await MyStorage.immutableUserDefinedType()).to.deep.equals(
BigNumber.from(constructorArgs._immutableUserDefinedType)
expect(await MyOtherImmutables.immutableUserDefinedType()).to.deep.equals(
BigNumber.from(immutableConstructorArgsTwo._immutableUserDefinedType)
)
})

it('does set immutable BigNumber int', async () => {
expect(await MyStorage.immutableBigNumberInt()).to.deep.equals(
constructorArgs._immutableBigNumberInt
expect(await MyOtherImmutables.immutableBigNumberInt()).to.deep.equals(
immutableConstructorArgsTwo._immutableBigNumberInt
)
})

it('does set immutable BigNumber uint', async () => {
expect(await MyStorage.immutableBigNumberUint()).to.deep.equals(
constructorArgs._immutableBigNumberUint
expect(await MyOtherImmutables.immutableBigNumberUint()).to.deep.equals(
immutableConstructorArgsTwo._immutableBigNumberUint
)
})

it('does set immutable address', async () => {
expect(await MyStorage.immutableAddress()).equals(
constructorArgs._immutableAddress
expect(await MyOtherImmutables.immutableAddress()).equals(
immutableConstructorArgsTwo._immutableAddress
)
})

it('does set immutable contract', async () => {
expect(await MyStorage.immutableContract()).equals(
constructorArgs._immutableContract
expect(await MyOtherImmutables.immutableContract()).equals(
immutableConstructorArgsTwo._immutableContract
)
})

it('does set immutable enum', async () => {
expect(await MyOtherImmutables.immutableEnum()).equals(
immutableConstructorArgsTwo._immutableEnum
)
})

Expand Down
5 changes: 4 additions & 1 deletion packages/plugins/test/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ export const invalidConstructorArgsPartTwo = {
},
}

export const constructorArgs = {
export const immutableConstructorArgsOne = {
_immutableInt: ethers.constants.MinInt256.toString(),
_immutableInt8: -128,
_immutableUint: ethers.constants.MaxUint256.toString(),
_immutableUint8: 255,
_immutableBool: true,
_immutableBytes32: '0x' + '11'.repeat(32),
}

export const immutableConstructorArgsTwo = {
_immutableUserDefinedType: ethers.constants.MaxUint256.toString(),
_immutableBigNumberUint: ethers.constants.MaxUint256,
_immutableBigNumberInt: ethers.constants.MinInt256,
Expand Down
Loading

0 comments on commit 1b0540c

Please sign in to comment.