ethereum / solidity-examples

Loose collection of Solidity example code
MIT License
534 stars 160 forks source link

Add tests for Patricia Tree contract #16

Open androlo opened 7 years ago

maxrobot commented 6 years ago

Hi @androlo I have tried to add some tests for the Patricia tree contract. I am following the tests from go-ethereum/trie/trie_test.go, but have implemented it in JS.

My test is as follows:

  it('Test: Insert()', async () => {
    const patricia = await Patricia.new();
    const accounts = web3.eth.accounts;

    let insertReceipt = await patricia.insert("A", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");

    // Get the root
    const rootReceipt = await patricia.getRootHash()
    const bytesRoot = hexToBytes(rootReceipt)

    const expectedRoot = hexToBytes("0xd23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab")
    assert.equal(expectedRoot, bytesRoot)
  })

The root produced is incorrect: Root Expected: 0xd23786fb4a010da3ce639d66d5e904a11dbc02746d1ce25029e53290cabf28ab Root Received: 0xe114ce969de5ac619a41bdb02ee5489d904389e803ca89461215a0b9a51528b5

Is this behaviour expected? I assume the implementation must be identical to that in go-ethereum...

Anyhow I will continue working at it :)