Skip to content

Commit

Permalink
fix(core): fix bug where int vars were encoded as uint
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-goldman committed Nov 27, 2022
1 parent bfd93a3 commit ec87d11
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/lemon-parents-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@chugsplash/core': patch
'@chugsplash/plugins': patch
---

Fixes bug where signed integers were encoded as unsigned integers
1 change: 0 additions & 1 deletion packages/core/src/languages/solidity/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ const encodeVariable = (
]
} else if (
variableType.label.startsWith('uint') ||
variableType.label.startsWith('int') ||
variableType.label.startsWith('enum')
) {
if (
Expand Down
3 changes: 2 additions & 1 deletion packages/plugins/chugsplash/SimpleStorage.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ChugSplashConfig } from '@chugsplash/core'
import { ethers } from 'ethers'

const config: ChugSplashConfig = {
// Configuration options for the project:
Expand All @@ -12,7 +13,7 @@ const config: ChugSplashConfig = {
FirstSimpleStorage: {
contract: 'SimpleStorage',
variables: {
testInt: 1,
testInt: ethers.constants.MinInt256.toString(),
number: 1,
stored: true,
storageName: 'First',
Expand Down
4 changes: 4 additions & 0 deletions packages/plugins/contracts/SimpleStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ contract SimpleStorage {
mapping(string => mapping(string => string)) public nestedMappingTest;
mapping(uint8 => mapping(string => mapping(address => uint))) public multiNestedMapping;

function getTestInt() external view returns (int) {
return testInt;
}

function getNumber() external view returns (uint8) {
return number;
}
Expand Down
8 changes: 7 additions & 1 deletion packages/plugins/test/SimpleStorage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai'
import { BigNumber, Contract } from 'ethers'
import { BigNumber, Contract, constants } from 'ethers'

describe('SimpleStorage', () => {
let FirstSimpleStorage: Contract
Expand All @@ -10,6 +10,12 @@ describe('SimpleStorage', () => {
FirstSimpleStorage = await chugsplash.getContract('FirstSimpleStorage')
})

it('does set int', async () => {
expect(await FirstSimpleStorage.getTestInt()).deep.equals(
constants.MinInt256
)
})

it('does set struct', async () => {
const struct = await FirstSimpleStorage.getStruct()
expect(struct[0]).equals(1)
Expand Down

0 comments on commit ec87d11

Please sign in to comment.