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

bounty: fix setVariable bug with arrays #81

Draft
wants to merge 1 commit into
base: main
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
18 changes: 18 additions & 0 deletions test/contracts/Test.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
contract Test {
mapping(uint256 => uint8[36]) public list;

function get_list(uint256 number) public view returns (uint8[36] memory _list) {
return list[number];
}

uint8[36] theList;
uint256[4] theList256;

function get_theList() public view returns (uint8[36] memory _theList) {
return theList;
}

function get_theList256() public view returns (uint256[4] memory _theList) {
return theList256;
}
}
57 changes: 57 additions & 0 deletions test/unit/mock/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { MockContract, MockContractFactory, smock } from '@src';
import { Test, Test__factory } from '@typechained';
import chai, { expect } from 'chai';

chai.use(smock.matchers);

describe.only('Skills', () => {
let test: MockContract<Test>;
let testFactory: MockContractFactory<Test__factory>;

before(async () => {
testFactory = await smock.mock('Test');
});

beforeEach(async () => {
test = await testFactory.deploy();
});

const list = [0, 0, 0, 0, 1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
// notice list.length = 36

describe('test', async () => {
it('should return list values in the correct order', async () => {
await test.setVariable('list', {
0: list,
});

const result = await test.get_list(0);
console.log(result);

expect(result).to.deep.eq(list);
});

it('should return theList values in the correct order', async () => {
await test.setVariable('theList', list);
const result = await test.get_theList();
console.log(result);

expect(result).to.deep.eq(list);
});

it('should return theList256 values in the correct order', async () => {
await test.setVariable('theList256', [1,2,3,4]);
const result = await test.get_theList256();
console.log(result);

expect(result).to.deep.eq([1,2,3,4]);
});

it('should or shouldnt allow an input value longer than 32 bytes', async () => {
await test.setVariable('list', {
// list has 36 spots, if first 4 are not left blank it reverts
0: [0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
});
});
});
});