EOSIO / eosjs

General purpose library for the EOSIO blockchain.
http://eosio.github.io/eosjs
MIT License
1.43k stars 463 forks source link

EOS Dawn3 API support #25

Closed jcalfee closed 6 years ago

chris-allnutt commented 6 years ago

I'll be updating the readme to advise users to use 2.x for now till dawn 3 is ready.

jcalfee commented 6 years ago

Related: https://github.com/EOSIO/eos/issues/1513 get_block ref_block_prefix needs to return uint32 (not a unit64) #1513

jcalfee commented 6 years ago

Related: https://github.com/EOSIO/eos/issues/1514 push_transaction API call is failing #1514

kesar commented 6 years ago

EOSIO/eos#1513 got merged 🎉 :) Is there any tag where I can start testing dawn3-eosjs?

jcalfee commented 6 years ago

The dawn3 branch in eosio/eosjs is still too buggy to use.. I'm working on it now.

jcalfee commented 6 years ago

In master, transaction actions print with an empty data attribute #1565 https://github.com/EOSIO/eos/issues/1565

jcalfee commented 6 years ago

Unit tests and README passing with github/eosio/eos[master] (pre-release of dawn3). Deployed to NPM, use a tag to get this version (7.0.0):

npm i eosjs@dawn3

The default at npm is still to install dawn2 compatible with the public testnet (6.x.x).

jcalfee commented 6 years ago

For examples, look at the README on the dawn3 branch: https://github.com/eosio/eosjs/tree/dawn3

jeremi commented 6 years ago

@jcalfee I have 2 issues with this branch for newaccount function. I think the expected parameters changed, so the Readme.md and the test is out of date (I'm using eosio master).

This format now work:

eos.newaccount({
        creator: 'eosio',
        name,
        owner: {"threshold": 1, "keys": [], "accounts": [{"permission":{ "actor":"jj.test", "permission":"active" }, "weight": 1}]},
        active: {"threshold": 1, "keys": [], "accounts": [{"permission":{ "actor":"jj.test", "permission":"active" }, "weight": 1}]},
        recovery: {"threshold": 1, "keys": [], "accounts": [{"permission":{ "actor":"jj.test", "permission":"active" }, "weight": 1}]}
      })

But when I try to use keys, I'm getting an error. My test is:

eos.newaccount({
        creator: 'eosio',
        name,
        owner: {"threshold": 1, "keys": [{"key": "EOS6ePVMSdSkGn4wDMqcCSTSN3GnRgEPxDPEioQQXUkfYxT8jrudg", "weight": 1}], "accounts": []},
        active: {"threshold": 1, "keys": [{"key": "EOS6ePVMSdSkGn4wDMqcCSTSN3GnRgEPxDPEioQQXUkfYxT8jrudg", "weight": 1}], "accounts": []},
        recovery: {"threshold": 1, "keys": [{"key": "EOS6ePVMSdSkGn4wDMqcCSTSN3GnRgEPxDPEioQQXUkfYxT8jrudg", "weight": 1}], "accounts": []}
      })

The error I get is:

"AssertionError: Checksum did not match, c9545447 != c9545447
    at Function.PublicKey.fromStringOrThrow (http://localhost:9080/static/eos.js:15168:12)
    at Object.appendByteBuffer (http://localhost:9080/static/eos.js:25811:29)
    at Object.appendByteBuffer (http://localhost:9080/static/eos.js:17505:12)
    at Object.appendByteBuffer (http://localhost:9080/static/eos.js:25781:21)
    at Object.appendByteBuffer (http://localhost:9080/static/eos.js:17105:20)
    at Object.appendByteBuffer (http://localhost:9080/static/eos.js:17565:16)
    at Object.appendByteBuffer (http://localhost:9080/static/eos.js:17105:20)
    at Object.appendByteBuffer (http://localhost:9080/static/eos.js:17105:20)
    at action.data.appendByteBuffer (http://localhost:9080/static/eos.js:26044:11)
    at Object.appendByteBuffer (http://localhost:9080/static/eos.js:17103:15)"

So it seems there is an issue when comparing the keys, even though they are the same. the issue seems to be because of assert.deepEqual as the object are not totally equal:

assert.deepEqual(checksum, new_checksum, 'Checksum did not match, ' + (checksum.toString('hex') + ' != ' + new_checksum.toString('hex')));

Changing it to the follow code fix the issue, but there is probably a more elegant solution:

assert.deepEqual(checksum.toString('hex')), new_checksum.toString('hex')), 'Checksum did not match, ' + (checksum.toString('hex') + ' != ' + new_checksum.toString('hex')));

Let me know if I should open a new ticket.

jcalfee commented 6 years ago

@jeremi should be fixed now in v7.0.1 and on the dawn3 branch..

jeremi commented 6 years ago

Yes, it's working now.

I think the tests will need to be fixed as the format of parameters changed: https://github.com/EOSIO/eosjs/blob/dawn3/src/index.test.js#L153

I did not run those tests automatically as I'm not sure how to set up the test environment, but running this test manually, it fail. It seems that because of line 57 those tests are not run by Travis automatically.

This doc is also outdated: https://github.com/EOSIO/eosjs/blame/dawn3/README.md#L145

jcalfee commented 6 years ago

Travis does not have a dawn3 node or a way to test with tokens, package.json forces testing locally before every npm publish.

The test and syntax works for me though, eosjs converts that syntax into the more expanded syntax your using: see 'short-hand' in the README. Both ways should work.