No funded issue found.
Check out the Issue Explorer
Be the OSS Funding you wish to see in the world.
Looking to fund some work? You can submit a new Funded Issue here .
Time left
Opened
Issue Type
Workers Auto Approve
Project Type
Time Commitment
Experience Level
Permissions
Accepted
Reserved For
[legacy] invalid passing of bool contract method arguments
ethereum-ts
TypeScript, JavaScript, Shell
## TL;DR
With the `legacy` target for web3-0.2.x, `bool` arguments in contract methods are passed through a `.toString()` in the generated TS class, which results in the argument always being set to `true` on the blockchain side.
Did not test with other targets.
## Minimal reproduction
### Contract
```solidity
contract TestContract {
bool public field;
event FieldSet(bool value);
function setField(bool _field) public {
field = _field;
emit FieldSet(field);
}
}
```
### Test
```ts
import { artifacts, contract, web3 } from './truffle-globals';
import { TestContract } from '@contracts/TestContract';
import { expect } from 'chai';
import { it } from 'mocha';
contract('TestContract', accounts => {
let testInstance: TestContract;
before(async () => {
const truffleDeployedContract = await artifacts
.require(TestContract.name)
.new({ from: accounts[0] });
testInstance = await TestContract.createAndValidate(
web3,
truffleDeployedContract.address,
);
});
it('tests setting the field', async () => {
expect(await testInstance.field).to.eq(false);
await testInstance.setFieldTx(true).send({ from: accounts[0] });
expect(await testInstance.field).to.eq(true);
});
it('tests unsetting the field', async () => {
expect(await testInstance.field).to.eq(true);
await testInstance.setFieldTx(false).send({ from: accounts[0] });
expect(await testInstance.field).to.eq(false);
});
});
```
### Test output
Most important detail: during the second test the emitted event says `value: true`, even though the method was called with `false`:
```
Contract: TestContract
✓ tests setting the field (68ms)
1) tests unsetting the field
Events emitted during test:
---------------------------
FieldSet(value: true)
---------------------------
1 passing (264ms)
1 failing
1) Contract: TestContract
tests unsetting the field:
AssertionError: expected true to equal false
+ expected - actual
-true
+false
at Object. (test/asdf.spec.ts:27:45)
at Generator.next ()
at fulfilled (test/asdf.spec.ts:4:58)
at
at process._tickCallback (internal/process/next_tick.js:182:7)
```
### Culprit
The `_field.toString()` argument in `TestContract.ts`.
When the `.toString()` conversion is removed manually, the test passes as expected.
```ts
public setFieldTx(
_field: boolean
): TC.DeferredTransactionWrapper {
return new TC.DeferredTransactionWrapper(this, "setField", [
_field.toString()
]);
}
```
### env
`typechain 0.3.8`
`web3 0.20.7`
`ganache-cli 6.1.8`
`truffle 4.1.13`
Setup your profile
Tell us a little about you:
Skills
No results found for [[search]] .
Type to search skills..
Bio Required
[[totalcharacter]] / 240
Are you currently looking for work?
[[ option.string ]]
Next
Setup your profile
Our tools are based on the principles of earn (💰), learn (📖), and meet (💬).
Select the ones you are interested in. You can change it later in your settings.
I'm also an organization manager looking for a great community.
Back
Next
Save
Enable your organization profile
Gitcoin products can help grow community around your brand. Create your tribe, events, and incentivize your community with bounties. Announce new and upcoming events using townsquare. Find top-quality hackers and fund them to work with you on a grant.
These are the organizations you own. If you don't see your organization here please be sure that information is public on your GitHub profile. Gitcoin will sync this information for you.
Select the products you are interested in:
Out of the box you will receive Tribes Lite for your organization. Please provide us with a contact email:
Email
Back
Save