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

Improve ethers compatibility #45

Merged
merged 3 commits into from
Dec 13, 2018

Conversation

andrewgordstewart
Copy link
Contributor

Using the provider's default signer provider.getSigner(0) is meant to fix the nonce-management issue that causes the the tx doesn't have the correct nonce. account has nonce of: 95 tx has nonce of: 94 error.

Sadly it still doesn't prevent flickering tests, for which we might have to wait for a fix, or switch to web3 contracts.

You can pass either an array or an object to an ethers.Contract method.
It's much nicer to deal with objects: when testing, you can, for
instance, expect this to pass
```
const arg = {
  x: "x",
  y: "y",
};

expect(await someContract.identityFunction(arg)).toMatchObject(arg);
```

If you create an array to pass as an argument, then you have to pull out
the attributes that ethers adds dynamically to the Array class, so that
you don't get something like
```
    Expected value to equal:
      ["0xB152A1F545EB049Aae89da0a5216d6546bDCAa83", {"_hex": "0x00"}, {"_hex": "0x02"}, ["0x6Ecbe1DB9EF729CBe972C83Fb886247691Fb6beb", "0xE36Ea790bc9d7AB70C55260C66D52b1eca985f84"], 3, {"_hex": "0x06"}, {"_hex": "0x00"}, [{"_hex": "0x06"}, {"_hex": "0x04"}], "0x0000000000000000000000000000000000000000000000000000000000000001"]
    Received:
      ["0xB152A1F545EB049Aae89da0a5216d6546bDCAa83", {"_hex": "0x00"}, {"_hex": "0x02"}, ["0x6Ecbe1DB9EF729CBe972C83Fb886247691Fb6beb", "0xE36Ea790bc9d7AB70C55260C66D52b1eca985f84"], 3, {"_hex": "0x06"}, {"_hex": "0x00"}, [{"_hex": "0x06"}, {"_hex": "0x04"}], "0x0000000000000000000000000000000000000000000000000000000000000001"]

    Difference:

    Compared values have no visual difference.
```

This is causerd by the fact that the second object, while it is an
`Array` object, also has a `channelType` attribute, whereas the first is
a pure `Array:
```
console.log((await turbo.getOutcome(turbo.address)).challengeState);
/**
// array values
    [ '0x2192af935893421b7a9c52d792b8e175F6486b2b',
      BigNumber { _hex: '0x00' },
      BigNumber { _hex: '0x02' },
      [ '0x6Ecbe1DB9EF729CBe972C83Fb886247691Fb6beb',
        '0xE36Ea790bc9d7AB70C55260C66D52b1eca985f84' ],
      3,
      BigNumber { _hex: '0x06' },
      BigNumber { _hex: '0x00' },
      [ BigNumber { _hex: '0x06' }, BigNumber { _hex: '0x04' } ],
      '0x0000000000000000000000000000000000000000000000000000000000000001',
// object attributes
      channelType: '0x2192af935893421b7a9c52d792b8e175F6486b2b',
      channelNonce: BigNumber { _hex: '0x00' },
      numberOfParticipants: BigNumber { _hex: '0x02' },
      participants: [ '0x6Ecbe1DB9EF729CBe972C83Fb886247691Fb6beb',
        '0xE36Ea790bc9d7AB70C55260C66D52b1eca985f84' ],
      stateType: 3,
      turnNum: BigNumber { _hex: '0x06' },
      stateCount: BigNumber { _hex: '0x00' },
      resolution: [ BigNumber { _hex: '0x06' }, BigNumber { _hex: '0x04' } ],
      gameAttributes: '0x0000000000000000000000000000000000000000000000000000000000000001' ]
**/
```
See discussion here: ethers-io/ethers.js#363
`await provider.getSigner().getAddress()` seems to have ether, though
it's not clear why?
@andrewgordstewart andrewgordstewart merged commit 8c302fe into master Dec 13, 2018
@andrewgordstewart andrewgordstewart deleted the as-improve-ethers-compatibility branch February 27, 2019 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants