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

[email protected] Block.toBuffer().toString('hex') not equal to rpc getblock(blockhash, 0) #175

Open
86chenjie opened this issue Sep 14, 2020 · 6 comments

Comments

@86chenjie
Copy link

test code:

it('check_block_hex', async function () {
    // test 147056 / 00000000000007a678f2e1316e0f7f7acf2b967d998558aed8dadcd4430fd5f1
    const height = 147056
    const blockhash = await chain.getblockhash(height)
    const chain_block_hex = await chain.getblock(blockhash, 0)
    const block = bsv.Block.fromBuffer(Buffer.from(chain_block_hex, 'hex'))
    const lib_block_hex = block.toBuffer().toString('hex')
    

    console.log(chain_block_hex)

    console.log(lib_block_hex)

    expect(chain_block_hex).to.equal(lib_block_hex);
  });

After hex compared, hex from bsv lib has extra '00000000', the result hex should be equal to rpc result.
image

@calvogenerico
Copy link
Contributor

Confirmed that this is happening. I rewrote the test using the tools used inside bsv and using a file instead of an rpc connection:

it.only('create block from hex and then serialize as hex returns the original hex', async () => {
    // const height = 147056
    // const blockHash = '00000000000007a678f2e1316e0f7f7acf2b967d998558aed8dadcd4430fd5f1'
    const blockHexRpc = await new Promise(resolve => {
      fs.readFile('test/block.txt', 'utf-8', (err, data) => {
        if (err) {
          throw err
        }
        resolve(data)
      })
    })

    const block = Block.fromBuffer(Buffer.from(blockHexRpc, 'hex'))
    const blockHexFromParsed = block.toBuffer().toString('hex')

    should(blockHexFromParsed).be.eql(blockHexRpc)
  })

This test fails exactly as described by @86chenjie. I'm looking for the cause.

@86chenjie
Copy link
Author

@hojarasca thanks for the response. Looking forward the fix. This issue really block my progress. Thanks again.

@86chenjie
Copy link
Author

any progress?

@86chenjie
Copy link
Author

@ryanxcharles can you help to check? Thanks!

@86chenjie
Copy link
Author

Workaround is here : 86chenjie@fe41812

@calvogenerico
Copy link
Contributor

@86chenjie thanks for the amazing job. I'm going to check your solution next week.

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

No branches or pull requests

2 participants