adjust statediff builder tests to changes and extend to test intermediate nodes; golint
This commit is contained in:
parent
c2c80f32d9
commit
d07dc803d2
@ -152,7 +152,7 @@ func (sdb *builder) collectDiffNodes(a, b trie.NodeIterator) (AccountsMap, error
|
||||
case Leaf:
|
||||
var account state.Account
|
||||
if err := rlp.DecodeBytes(nodeElements[1].([]byte), &account); err != nil {
|
||||
return nil, fmt.Errorf("error decoding account for leaf node at path %x\r\nerror: %v\r\n", nodePath, err)
|
||||
return nil, fmt.Errorf("error decoding account for leaf node at path %x nerror: %v", nodePath, err)
|
||||
}
|
||||
partialPath := trie.CompactToHex(nodeElements[0].([]byte))
|
||||
valueNodePath := append(nodePath, partialPath...)
|
||||
|
@ -40,7 +40,7 @@ var (
|
||||
builder statediff.Builder
|
||||
miningReward = int64(2000000000000000000)
|
||||
minerAddress = common.HexToAddress("0x0")
|
||||
minerLeafKey = testhelpers.AddressToEncodedPath(minerAddress)
|
||||
minerLeafKey = testhelpers.AddressToLeafKey(minerAddress)
|
||||
|
||||
balanceChange10000 = int64(10000)
|
||||
balanceChange1000 = int64(1000)
|
||||
@ -55,18 +55,22 @@ var (
|
||||
contractContractRoot = "0x821e2556a290c86405f8160a2d662042a431ba456b9db265c79bb837c04be5f0"
|
||||
newContractRoot = "0x71e0d14b2b93e5c7f9748e69e1fe5f17498a1c3ac3cec29f96af13d7f8a4e070"
|
||||
originalStorageLocation = common.HexToHash("0")
|
||||
originalStorageKey = append(testhelpers.EvenLeafFlag, crypto.Keccak256Hash(originalStorageLocation[:]).Bytes()...)
|
||||
updatedStorageLocation = common.HexToHash("2")
|
||||
updatedStorageKey = append(testhelpers.EvenLeafFlag, crypto.Keccak256Hash(updatedStorageLocation[:]).Bytes()...)
|
||||
originalStorageKey = crypto.Keccak256Hash(originalStorageLocation[:]).Bytes()
|
||||
newStorageLocation = common.HexToHash("2")
|
||||
newStorageKey = crypto.Keccak256Hash(newStorageLocation[:]).Bytes()
|
||||
originalStorageValue = common.Hex2Bytes("01")
|
||||
originalStorageLeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
common.Hex2Bytes("20290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563"),
|
||||
originalStorageValue,
|
||||
})
|
||||
updatedStorageValue = common.Hex2Bytes("03")
|
||||
updatedStorageLeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
common.Hex2Bytes("390decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563"),
|
||||
originalStorageValue,
|
||||
})
|
||||
newStorageValue = common.Hex2Bytes("03")
|
||||
newStorageLeafNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
common.Hex2Bytes("305787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace"),
|
||||
updatedStorageValue,
|
||||
newStorageValue,
|
||||
})
|
||||
account1AtBlock1, _ = rlp.EncodeToBytes(state.Account{
|
||||
Nonce: nonce0,
|
||||
@ -178,6 +182,83 @@ var (
|
||||
common.Hex2Bytes("30bf49f440a1cd0527e4d06e2765654c0f56452257516d793a9b8d604dcfdf2a"),
|
||||
bankAccountAtBlock3,
|
||||
})
|
||||
|
||||
block1BranchNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
crypto.Keccak256(bankAccountAtBlock1LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
crypto.Keccak256(minerAccountAtBlock1LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
crypto.Keccak256(account1AtBlock1LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
})
|
||||
block2BranchNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
crypto.Keccak256(bankAccountAtBlock2LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
crypto.Keccak256(minerAccountAtBlock2LeafNode),
|
||||
crypto.Keccak256(contractAccountAtBlock2LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
crypto.Keccak256(account2AtBlock2LeafNode),
|
||||
[]byte{},
|
||||
crypto.Keccak256(account1AtBlock2LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
})
|
||||
block3BranchNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
crypto.Keccak256(bankAccountAtBlock3LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
crypto.Keccak256(minerAccountAtBlock2LeafNode),
|
||||
crypto.Keccak256(contractAccountAtBlock3LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
crypto.Keccak256(account2AtBlock3LeafNode),
|
||||
[]byte{},
|
||||
crypto.Keccak256(account1AtBlock2LeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
})
|
||||
block3StorageBranchNode, _ = rlp.EncodeToBytes([]interface{}{
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
crypto.Keccak256(updatedStorageLeafNode),
|
||||
[]byte{},
|
||||
crypto.Keccak256(newStorageLeafNode),
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
[]byte{},
|
||||
})
|
||||
)
|
||||
|
||||
type arguments struct {
|
||||
@ -187,16 +268,15 @@ type arguments struct {
|
||||
blockHash common.Hash
|
||||
}
|
||||
|
||||
func TestBuilder(t *testing.T) {
|
||||
func TestBuilder1(t *testing.T) {
|
||||
blockHashes, blockMap, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
|
||||
contractLeafKey = testhelpers.AddressToEncodedPath(testhelpers.ContractAddr)
|
||||
contractLeafKey = testhelpers.AddressToLeafKey(testhelpers.ContractAddr)
|
||||
defer chain.Stop()
|
||||
block0 = blockMap[blockHashes[3]]
|
||||
block1 = blockMap[blockHashes[2]]
|
||||
block2 = blockMap[blockHashes[1]]
|
||||
block3 = blockMap[blockHashes[0]]
|
||||
config := statediff.Config{
|
||||
LeafProofs: true,
|
||||
IntermediateNodes: false,
|
||||
}
|
||||
builder = statediff.NewBuilder(chain, config)
|
||||
@ -237,31 +317,28 @@ func TestBuilder(t *testing.T) {
|
||||
BlockHash: block1.Hash(),
|
||||
CreatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: minerLeafKey,
|
||||
NodeValue: minerAccountAtBlock1LeafNode,
|
||||
Proof: [][]byte{{248, 113, 160, 87, 118, 82, 182, 37, 183, 123, 219, 91, 247, 123, 196, 63, 49, 37, 202, 215, 70, 77, 103, 157, 21, 117, 86, 82, 119, 211, 97, 27, 128, 83, 231, 128, 128, 128, 128, 160, 254, 136, 159, 16, 229, 219, 143, 44, 43, 243, 85, 146, 129, 82, 161, 127, 110, 59, 185, 154, 146, 65, 172, 109, 132, 199, 126, 98, 100, 80, 156, 121, 128, 128, 128, 128, 128, 128, 128, 128, 160, 17, 219, 12, 218, 52, 168, 150, 218, 190, 182, 131, 155, 176, 106, 56, 244, 149, 20, 207, 164, 134, 67, 89, 132, 235, 1, 59, 125, 249, 238, 133, 197, 128, 128},
|
||||
{248, 113, 160, 51, 128, 199, 183, 174, 129, 165, 142, 185, 141, 156, 120, 222, 74, 31, 215, 253, 149, 53, 252, 149, 62, 210, 190, 96, 45, 170, 164, 23, 103, 49, 42, 184, 78, 248, 76, 128, 136, 27, 193, 109, 103, 78, 200, 0, 0, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x05'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: minerLeafKey,
|
||||
NodeValue: minerAccountAtBlock1LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: testhelpers.Account1LeafKey,
|
||||
NodeValue: account1AtBlock1LeafNode,
|
||||
Proof: [][]byte{{248, 113, 160, 87, 118, 82, 182, 37, 183, 123, 219, 91, 247, 123, 196, 63, 49, 37, 202, 215, 70, 77, 103, 157, 21, 117, 86, 82, 119, 211, 97, 27, 128, 83, 231, 128, 128, 128, 128, 160, 254, 136, 159, 16, 229, 219, 143, 44, 43, 243, 85, 146, 129, 82, 161, 127, 110, 59, 185, 154, 146, 65, 172, 109, 132, 199, 126, 98, 100, 80, 156, 121, 128, 128, 128, 128, 128, 128, 128, 128, 160, 17, 219, 12, 218, 52, 168, 150, 218, 190, 182, 131, 155, 176, 106, 56, 244, 149, 20, 207, 164, 134, 67, 89, 132, 235, 1, 59, 125, 249, 238, 133, 197, 128, 128},
|
||||
{248, 107, 160, 57, 38, 219, 105, 170, 206, 213, 24, 233, 185, 240, 244, 52, 164, 115, 231, 23, 65, 9, 201, 67, 84, 139, 184, 242, 59, 228, 28, 167, 109, 154, 210, 184, 72, 248, 70, 128, 130, 39, 16, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x0e'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.Account1LeafKey,
|
||||
NodeValue: account1AtBlock1LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||
UpdatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: testhelpers.BankLeafKey,
|
||||
NodeValue: bankAccountAtBlock1LeafNode,
|
||||
Proof: [][]byte{{248, 113, 160, 87, 118, 82, 182, 37, 183, 123, 219, 91, 247, 123, 196, 63, 49, 37, 202, 215, 70, 77, 103, 157, 21, 117, 86, 82, 119, 211, 97, 27, 128, 83, 231, 128, 128, 128, 128, 160, 254, 136, 159, 16, 229, 219, 143, 44, 43, 243, 85, 146, 129, 82, 161, 127, 110, 59, 185, 154, 146, 65, 172, 109, 132, 199, 126, 98, 100, 80, 156, 121, 128, 128, 128, 128, 128, 128, 128, 128, 160, 17, 219, 12, 218, 52, 168, 150, 218, 190, 182, 131, 155, 176, 106, 56, 244, 149, 20, 207, 164, 134, 67, 89, 132, 235, 1, 59, 125, 249, 238, 133, 197, 128, 128},
|
||||
{248, 109, 160, 48, 191, 73, 244, 64, 161, 205, 5, 39, 228, 208, 110, 39, 101, 101, 76, 15, 86, 69, 34, 87, 81, 109, 121, 58, 155, 141, 96, 77, 207, 223, 42, 184, 74, 248, 72, 1, 132, 5, 245, 185, 240, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x00'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.BankLeafKey,
|
||||
NodeValue: bankAccountAtBlock1LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -282,54 +359,49 @@ func TestBuilder(t *testing.T) {
|
||||
BlockHash: block2.Hash(),
|
||||
CreatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: contractLeafKey,
|
||||
NodeValue: contractAccountAtBlock2LeafNode,
|
||||
Proof: [][]byte{{248, 177, 160, 177, 155, 238, 178, 242, 47, 83, 2, 49, 141, 155, 92, 149, 175, 245, 120, 233, 177, 101, 67, 46, 200, 23, 250, 41, 74, 135, 94, 61, 133, 51, 162, 128, 128, 128, 128, 160, 179, 86, 53, 29, 96, 188, 152, 148, 207, 31, 29, 108, 182, 140, 129, 95, 1, 49, 213, 15, 29, 168, 60, 64, 35, 160, 158, 200, 85, 207, 255, 145, 160, 114, 57, 32, 11, 115, 232, 140, 238, 165, 222, 121, 226, 208, 2, 192, 216, 67, 198, 179, 31, 181, 27, 208, 243, 99, 202, 48, 148, 207, 107, 106, 177, 128, 128, 128, 128, 128, 160, 10, 173, 165, 125, 110, 240, 77, 112, 149, 100, 135, 237, 25, 228, 116, 7, 195, 9, 210, 166, 208, 148, 101, 23, 244, 238, 84, 84, 211, 249, 138, 137, 128, 160, 255, 115, 147, 190, 57, 135, 174, 188, 86, 51, 227, 70, 22, 253, 237, 49, 24, 19, 149, 199, 142, 195, 186, 244, 70, 51, 138, 0, 146, 148, 117, 60, 128, 128},
|
||||
{248, 105, 160, 49, 20, 101, 138, 116, 217, 204, 159, 122, 207, 44, 92, 214, 150, 195, 73, 77, 124, 52, 77, 120, 191, 236, 58, 221, 13, 145, 236, 78, 141, 28, 69, 184, 70, 248, 68, 1, 128, 160, 130, 30, 37, 86, 162, 144, 200, 100, 5, 248, 22, 10, 45, 102, 32, 66, 164, 49, 186, 69, 107, 157, 178, 101, 199, 155, 184, 55, 192, 75, 229, 240, 160, 117, 63, 152, 168, 212, 50, 139, 21, 99, 110, 70, 246, 111, 44, 180, 188, 134, 1, 0, 170, 23, 150, 124, 193, 69, 252, 209, 125, 29, 71, 16, 234}},
|
||||
Path: []byte{'\x06'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: contractLeafKey,
|
||||
NodeValue: contractAccountAtBlock2LeafNode,
|
||||
Storage: []statediff.StorageDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: originalStorageKey,
|
||||
NodeValue: originalStorageLeafNode,
|
||||
Proof: [][]byte{{227, 161, 32, 41, 13, 236, 217, 84, 139, 98, 168, 214, 3, 69, 169, 136, 56, 111, 200, 75, 166, 188, 149, 72, 64, 8, 246, 54, 47, 147, 22, 14, 243, 229, 99, 1}},
|
||||
Path: []byte{},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: originalStorageKey,
|
||||
NodeValue: originalStorageLeafNode,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: testhelpers.Account2LeafKey,
|
||||
NodeValue: account2AtBlock2LeafNode,
|
||||
Proof: [][]byte{{248, 177, 160, 177, 155, 238, 178, 242, 47, 83, 2, 49, 141, 155, 92, 149, 175, 245, 120, 233, 177, 101, 67, 46, 200, 23, 250, 41, 74, 135, 94, 61, 133, 51, 162, 128, 128, 128, 128, 160, 179, 86, 53, 29, 96, 188, 152, 148, 207, 31, 29, 108, 182, 140, 129, 95, 1, 49, 213, 15, 29, 168, 60, 64, 35, 160, 158, 200, 85, 207, 255, 145, 160, 114, 57, 32, 11, 115, 232, 140, 238, 165, 222, 121, 226, 208, 2, 192, 216, 67, 198, 179, 31, 181, 27, 208, 243, 99, 202, 48, 148, 207, 107, 106, 177, 128, 128, 128, 128, 128, 160, 10, 173, 165, 125, 110, 240, 77, 112, 149, 100, 135, 237, 25, 228, 116, 7, 195, 9, 210, 166, 208, 148, 101, 23, 244, 238, 84, 84, 211, 249, 138, 137, 128, 160, 255, 115, 147, 190, 57, 135, 174, 188, 86, 51, 227, 70, 22, 253, 237, 49, 24, 19, 149, 199, 142, 195, 186, 244, 70, 51, 138, 0, 146, 148, 117, 60, 128, 128},
|
||||
{248, 107, 160, 57, 87, 243, 226, 240, 74, 7, 100, 195, 160, 73, 27, 23, 95, 105, 146, 109, 166, 30, 251, 204, 143, 97, 250, 20, 85, 253, 45, 43, 76, 221, 69, 184, 72, 248, 70, 128, 130, 3, 232, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x0c'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.Account2LeafKey,
|
||||
NodeValue: account2AtBlock2LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||
UpdatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: testhelpers.BankLeafKey,
|
||||
NodeValue: bankAccountAtBlock2LeafNode,
|
||||
Proof: [][]byte{{248, 177, 160, 177, 155, 238, 178, 242, 47, 83, 2, 49, 141, 155, 92, 149, 175, 245, 120, 233, 177, 101, 67, 46, 200, 23, 250, 41, 74, 135, 94, 61, 133, 51, 162, 128, 128, 128, 128, 160, 179, 86, 53, 29, 96, 188, 152, 148, 207, 31, 29, 108, 182, 140, 129, 95, 1, 49, 213, 15, 29, 168, 60, 64, 35, 160, 158, 200, 85, 207, 255, 145, 160, 114, 57, 32, 11, 115, 232, 140, 238, 165, 222, 121, 226, 208, 2, 192, 216, 67, 198, 179, 31, 181, 27, 208, 243, 99, 202, 48, 148, 207, 107, 106, 177, 128, 128, 128, 128, 128, 160, 10, 173, 165, 125, 110, 240, 77, 112, 149, 100, 135, 237, 25, 228, 116, 7, 195, 9, 210, 166, 208, 148, 101, 23, 244, 238, 84, 84, 211, 249, 138, 137, 128, 160, 255, 115, 147, 190, 57, 135, 174, 188, 86, 51, 227, 70, 22, 253, 237, 49, 24, 19, 149, 199, 142, 195, 186, 244, 70, 51, 138, 0, 146, 148, 117, 60, 128, 128},
|
||||
{248, 109, 160, 48, 191, 73, 244, 64, 161, 205, 5, 39, 228, 208, 110, 39, 101, 101, 76, 15, 86, 69, 34, 87, 81, 109, 121, 58, 155, 141, 96, 77, 207, 223, 42, 184, 74, 248, 72, 2, 132, 5, 245, 182, 8, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x00'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.BankLeafKey,
|
||||
NodeValue: bankAccountAtBlock2LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: minerLeafKey,
|
||||
NodeValue: minerAccountAtBlock2LeafNode,
|
||||
Proof: [][]byte{{248, 177, 160, 177, 155, 238, 178, 242, 47, 83, 2, 49, 141, 155, 92, 149, 175, 245, 120, 233, 177, 101, 67, 46, 200, 23, 250, 41, 74, 135, 94, 61, 133, 51, 162, 128, 128, 128, 128, 160, 179, 86, 53, 29, 96, 188, 152, 148, 207, 31, 29, 108, 182, 140, 129, 95, 1, 49, 213, 15, 29, 168, 60, 64, 35, 160, 158, 200, 85, 207, 255, 145, 160, 114, 57, 32, 11, 115, 232, 140, 238, 165, 222, 121, 226, 208, 2, 192, 216, 67, 198, 179, 31, 181, 27, 208, 243, 99, 202, 48, 148, 207, 107, 106, 177, 128, 128, 128, 128, 128, 160, 10, 173, 165, 125, 110, 240, 77, 112, 149, 100, 135, 237, 25, 228, 116, 7, 195, 9, 210, 166, 208, 148, 101, 23, 244, 238, 84, 84, 211, 249, 138, 137, 128, 160, 255, 115, 147, 190, 57, 135, 174, 188, 86, 51, 227, 70, 22, 253, 237, 49, 24, 19, 149, 199, 142, 195, 186, 244, 70, 51, 138, 0, 146, 148, 117, 60, 128, 128},
|
||||
{248, 113, 160, 51, 128, 199, 183, 174, 129, 165, 142, 185, 141, 156, 120, 222, 74, 31, 215, 253, 149, 53, 252, 149, 62, 210, 190, 96, 45, 170, 164, 23, 103, 49, 42, 184, 78, 248, 76, 128, 136, 55, 130, 218, 206, 157, 144, 0, 0, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x05'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: minerLeafKey,
|
||||
NodeValue: minerAccountAtBlock2LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: testhelpers.Account1LeafKey,
|
||||
NodeValue: account1AtBlock2LeafNode,
|
||||
Proof: [][]byte{{248, 177, 160, 177, 155, 238, 178, 242, 47, 83, 2, 49, 141, 155, 92, 149, 175, 245, 120, 233, 177, 101, 67, 46, 200, 23, 250, 41, 74, 135, 94, 61, 133, 51, 162, 128, 128, 128, 128, 160, 179, 86, 53, 29, 96, 188, 152, 148, 207, 31, 29, 108, 182, 140, 129, 95, 1, 49, 213, 15, 29, 168, 60, 64, 35, 160, 158, 200, 85, 207, 255, 145, 160, 114, 57, 32, 11, 115, 232, 140, 238, 165, 222, 121, 226, 208, 2, 192, 216, 67, 198, 179, 31, 181, 27, 208, 243, 99, 202, 48, 148, 207, 107, 106, 177, 128, 128, 128, 128, 128, 160, 10, 173, 165, 125, 110, 240, 77, 112, 149, 100, 135, 237, 25, 228, 116, 7, 195, 9, 210, 166, 208, 148, 101, 23, 244, 238, 84, 84, 211, 249, 138, 137, 128, 160, 255, 115, 147, 190, 57, 135, 174, 188, 86, 51, 227, 70, 22, 253, 237, 49, 24, 19, 149, 199, 142, 195, 186, 244, 70, 51, 138, 0, 146, 148, 117, 60, 128, 128},
|
||||
{248, 107, 160, 57, 38, 219, 105, 170, 206, 213, 24, 233, 185, 240, 244, 52, 164, 115, 231, 23, 65, 9, 201, 67, 84, 139, 184, 242, 59, 228, 28, 167, 109, 154, 210, 184, 72, 248, 70, 2, 130, 39, 16, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x0e'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.Account1LeafKey,
|
||||
NodeValue: account1AtBlock2LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -351,36 +423,38 @@ func TestBuilder(t *testing.T) {
|
||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||
UpdatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: testhelpers.BankLeafKey,
|
||||
NodeValue: bankAccountAtBlock3LeafNode,
|
||||
Proof: [][]byte{{248, 177, 160, 101, 223, 138, 81, 34, 40, 229, 170, 198, 188, 136, 99, 7, 55, 33, 112, 160, 111, 181, 131, 167, 201, 131, 24, 201, 211, 177, 30, 159, 229, 246, 6, 128, 128, 128, 128, 160, 179, 86, 53, 29, 96, 188, 152, 148, 207, 31, 29, 108, 182, 140, 129, 95, 1, 49, 213, 15, 29, 168, 60, 64, 35, 160, 158, 200, 85, 207, 255, 145, 160, 32, 135, 108, 213, 150, 150, 110, 44, 170, 65, 75, 154, 74, 249, 94, 65, 74, 107, 100, 115, 39, 5, 3, 26, 22, 238, 138, 114, 254, 21, 6, 171, 128, 128, 128, 128, 128, 160, 4, 228, 121, 222, 255, 218, 60, 247, 15, 0, 34, 198, 28, 229, 180, 129, 109, 157, 68, 181, 248, 229, 200, 123, 29, 81, 145, 114, 90, 209, 205, 210, 128, 160, 255, 115, 147, 190, 57, 135, 174, 188, 86, 51, 227, 70, 22, 253, 237, 49, 24, 19, 149, 199, 142, 195, 186, 244, 70, 51, 138, 0, 146, 148, 117, 60, 128, 128},
|
||||
{248, 109, 160, 48, 191, 73, 244, 64, 161, 205, 5, 39, 228, 208, 110, 39, 101, 101, 76, 15, 86, 69, 34, 87, 81, 109, 121, 58, 155, 141, 96, 77, 207, 223, 42, 184, 74, 248, 72, 3, 132, 5, 245, 182, 8, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x00'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.BankLeafKey,
|
||||
NodeValue: bankAccountAtBlock3LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: contractLeafKey,
|
||||
NodeValue: contractAccountAtBlock3LeafNode,
|
||||
Proof: [][]byte{{248, 177, 160, 101, 223, 138, 81, 34, 40, 229, 170, 198, 188, 136, 99, 7, 55, 33, 112, 160, 111, 181, 131, 167, 201, 131, 24, 201, 211, 177, 30, 159, 229, 246, 6, 128, 128, 128, 128, 160, 179, 86, 53, 29, 96, 188, 152, 148, 207, 31, 29, 108, 182, 140, 129, 95, 1, 49, 213, 15, 29, 168, 60, 64, 35, 160, 158, 200, 85, 207, 255, 145, 160, 32, 135, 108, 213, 150, 150, 110, 44, 170, 65, 75, 154, 74, 249, 94, 65, 74, 107, 100, 115, 39, 5, 3, 26, 22, 238, 138, 114, 254, 21, 6, 171, 128, 128, 128, 128, 128, 160, 4, 228, 121, 222, 255, 218, 60, 247, 15, 0, 34, 198, 28, 229, 180, 129, 109, 157, 68, 181, 248, 229, 200, 123, 29, 81, 145, 114, 90, 209, 205, 210, 128, 160, 255, 115, 147, 190, 57, 135, 174, 188, 86, 51, 227, 70, 22, 253, 237, 49, 24, 19, 149, 199, 142, 195, 186, 244, 70, 51, 138, 0, 146, 148, 117, 60, 128, 128},
|
||||
{248, 105, 160, 49, 20, 101, 138, 116, 217, 204, 159, 122, 207, 44, 92, 214, 150, 195, 73, 77, 124, 52, 77, 120, 191, 236, 58, 221, 13, 145, 236, 78, 141, 28, 69, 184, 70, 248, 68, 1, 128, 160, 113, 224, 209, 75, 43, 147, 229, 199, 249, 116, 142, 105, 225, 254, 95, 23, 73, 138, 28, 58, 195, 206, 194, 159, 150, 175, 19, 215, 248, 164, 224, 112, 160, 117, 63, 152, 168, 212, 50, 139, 21, 99, 110, 70, 246, 111, 44, 180, 188, 134, 1, 0, 170, 23, 150, 124, 193, 69, 252, 209, 125, 29, 71, 16, 234}},
|
||||
Path: []byte{'\x06'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: contractLeafKey,
|
||||
NodeValue: contractAccountAtBlock3LeafNode,
|
||||
Storage: []statediff.StorageDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: updatedStorageKey,
|
||||
NodeValue: updatedStorageLeafNode,
|
||||
Proof: [][]byte{{248, 81, 128, 128, 160, 79, 197, 241, 58, 178, 249, 186, 12, 45, 168, 139, 1, 81, 171, 14, 124, 244, 216, 93, 8, 204, 164, 92, 205, 146, 60, 106, 183, 99, 35, 235, 40, 128, 160, 205, 69, 114, 89, 105, 97, 21, 35, 94, 100, 199, 130, 35, 52, 214, 33, 41, 226, 241, 96, 68, 37, 167, 218, 100, 148, 243, 95, 196, 91, 229, 24, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128},
|
||||
{226, 160, 48, 87, 135, 250, 18, 168, 35, 224, 242, 183, 99, 28, 196, 27, 59, 168, 130, 139, 51, 33, 202, 129, 17, 17, 250, 117, 205, 58, 163, 187, 90, 206, 3}},
|
||||
Path: []byte{'\x02'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: originalStorageKey,
|
||||
NodeValue: updatedStorageLeafNode,
|
||||
},
|
||||
{
|
||||
Path: []byte{'\x04'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: newStorageKey,
|
||||
NodeValue: newStorageLeafNode,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: testhelpers.Account2LeafKey,
|
||||
NodeValue: account2AtBlock3LeafNode,
|
||||
Proof: [][]byte{{248, 177, 160, 101, 223, 138, 81, 34, 40, 229, 170, 198, 188, 136, 99, 7, 55, 33, 112, 160, 111, 181, 131, 167, 201, 131, 24, 201, 211, 177, 30, 159, 229, 246, 6, 128, 128, 128, 128, 160, 179, 86, 53, 29, 96, 188, 152, 148, 207, 31, 29, 108, 182, 140, 129, 95, 1, 49, 213, 15, 29, 168, 60, 64, 35, 160, 158, 200, 85, 207, 255, 145, 160, 32, 135, 108, 213, 150, 150, 110, 44, 170, 65, 75, 154, 74, 249, 94, 65, 74, 107, 100, 115, 39, 5, 3, 26, 22, 238, 138, 114, 254, 21, 6, 171, 128, 128, 128, 128, 128, 160, 4, 228, 121, 222, 255, 218, 60, 247, 15, 0, 34, 198, 28, 229, 180, 129, 109, 157, 68, 181, 248, 229, 200, 123, 29, 81, 145, 114, 90, 209, 205, 210, 128, 160, 255, 115, 147, 190, 57, 135, 174, 188, 86, 51, 227, 70, 22, 253, 237, 49, 24, 19, 149, 199, 142, 195, 186, 244, 70, 51, 138, 0, 146, 148, 117, 60, 128, 128},
|
||||
{248, 113, 160, 57, 87, 243, 226, 240, 74, 7, 100, 195, 160, 73, 27, 23, 95, 105, 146, 109, 166, 30, 251, 204, 143, 97, 250, 20, 85, 253, 45, 43, 76, 221, 69, 184, 78, 248, 76, 128, 136, 27, 193, 109, 103, 78, 200, 3, 232, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x0c'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.Account2LeafKey,
|
||||
NodeValue: account2AtBlock3LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -405,21 +479,259 @@ func TestBuilder(t *testing.T) {
|
||||
sort.Slice(expectedStateDiffRlp, func(i, j int) bool { return expectedStateDiffRlp[i] < expectedStateDiffRlp[j] })
|
||||
if !bytes.Equal(receivedStateDiffRlp, expectedStateDiffRlp) {
|
||||
t.Logf("Test failed: %s", test.name)
|
||||
t.Errorf("actual state diff rlp: %+v\nexpected state diff rlp: %+v", receivedStateDiffRlp, expectedStateDiffRlp)
|
||||
t.Errorf("actual state diff: %+v\nexpected state diff: %+v", diff, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuilderWithWatchedAddressList(t *testing.T) {
|
||||
func TestBuilderWithIntermediateNodes(t *testing.T) {
|
||||
blockHashes, blockMap, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
|
||||
contractLeafKey = testhelpers.AddressToEncodedPath(testhelpers.ContractAddr)
|
||||
contractLeafKey = testhelpers.AddressToLeafKey(testhelpers.ContractAddr)
|
||||
defer chain.Stop()
|
||||
block0 = blockMap[blockHashes[3]]
|
||||
block1 = blockMap[blockHashes[2]]
|
||||
block2 = blockMap[blockHashes[1]]
|
||||
block3 = blockMap[blockHashes[0]]
|
||||
config := statediff.Config{
|
||||
IntermediateNodes: true,
|
||||
}
|
||||
builder = statediff.NewBuilder(chain, config)
|
||||
|
||||
var tests = []struct {
|
||||
name string
|
||||
startingArguments arguments
|
||||
expected *statediff.StateDiff
|
||||
}{
|
||||
{
|
||||
"testEmptyDiff",
|
||||
arguments{
|
||||
oldStateRoot: block0.Root(),
|
||||
newStateRoot: block0.Root(),
|
||||
blockNumber: block0.Number(),
|
||||
blockHash: block0.Hash(),
|
||||
},
|
||||
&statediff.StateDiff{
|
||||
BlockNumber: block0.Number(),
|
||||
BlockHash: block0.Hash(),
|
||||
CreatedAccounts: emptyAccountDiffEventualMap,
|
||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||
UpdatedAccounts: emptyAccountDiffIncrementalMap,
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
"testBlock1",
|
||||
//10000 transferred from testBankAddress to account1Addr
|
||||
arguments{
|
||||
oldStateRoot: block0.Root(),
|
||||
newStateRoot: block1.Root(),
|
||||
blockNumber: block1.Number(),
|
||||
blockHash: block1.Hash(),
|
||||
},
|
||||
&statediff.StateDiff{
|
||||
BlockNumber: block1.Number(),
|
||||
BlockHash: block1.Hash(),
|
||||
CreatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
Path: []byte{},
|
||||
NodeType: statediff.Branch,
|
||||
NodeValue: block1BranchNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
{
|
||||
Path: []byte{'\x05'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: minerLeafKey,
|
||||
NodeValue: minerAccountAtBlock1LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
{
|
||||
Path: []byte{'\x0e'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.Account1LeafKey,
|
||||
NodeValue: account1AtBlock1LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||
UpdatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
Path: []byte{'\x00'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.BankLeafKey,
|
||||
NodeValue: bankAccountAtBlock1LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"testBlock2",
|
||||
// 1000 transferred from testBankAddress to account1Addr
|
||||
// 1000 transferred from account1Addr to account2Addr
|
||||
// account1addr creates a new contract
|
||||
arguments{
|
||||
oldStateRoot: block1.Root(),
|
||||
newStateRoot: block2.Root(),
|
||||
blockNumber: block2.Number(),
|
||||
blockHash: block2.Hash(),
|
||||
},
|
||||
&statediff.StateDiff{
|
||||
BlockNumber: block2.Number(),
|
||||
BlockHash: block2.Hash(),
|
||||
CreatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
Path: []byte{'\x06'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: contractLeafKey,
|
||||
NodeValue: contractAccountAtBlock2LeafNode,
|
||||
Storage: []statediff.StorageDiff{
|
||||
{
|
||||
Path: []byte{},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: originalStorageKey,
|
||||
NodeValue: originalStorageLeafNode,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Path: []byte{'\x0c'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.Account2LeafKey,
|
||||
NodeValue: account2AtBlock2LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||
UpdatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
Path: []byte{},
|
||||
NodeType: statediff.Branch,
|
||||
NodeValue: block2BranchNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
{
|
||||
Path: []byte{'\x00'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.BankLeafKey,
|
||||
NodeValue: bankAccountAtBlock2LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
{
|
||||
Path: []byte{'\x05'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: minerLeafKey,
|
||||
NodeValue: minerAccountAtBlock2LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
{
|
||||
Path: []byte{'\x0e'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.Account1LeafKey,
|
||||
NodeValue: account1AtBlock2LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
"testBlock3",
|
||||
//the contract's storage is changed
|
||||
//and the block is mined by account 2
|
||||
arguments{
|
||||
oldStateRoot: block2.Root(),
|
||||
newStateRoot: block3.Root(),
|
||||
blockNumber: block3.Number(),
|
||||
blockHash: block3.Hash(),
|
||||
},
|
||||
&statediff.StateDiff{
|
||||
BlockNumber: block3.Number(),
|
||||
BlockHash: block3.Hash(),
|
||||
CreatedAccounts: []statediff.AccountDiff{},
|
||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||
UpdatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
Path: []byte{},
|
||||
NodeType: statediff.Branch,
|
||||
NodeValue: block3BranchNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
{
|
||||
Path: []byte{'\x00'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.BankLeafKey,
|
||||
NodeValue: bankAccountAtBlock3LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
{
|
||||
Path: []byte{'\x06'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: contractLeafKey,
|
||||
NodeValue: contractAccountAtBlock3LeafNode,
|
||||
Storage: []statediff.StorageDiff{
|
||||
{
|
||||
Path: []byte{},
|
||||
NodeType: statediff.Branch,
|
||||
NodeValue: block3StorageBranchNode,
|
||||
},
|
||||
{
|
||||
Path: []byte{'\x02'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: originalStorageKey,
|
||||
NodeValue: updatedStorageLeafNode,
|
||||
},
|
||||
{
|
||||
Path: []byte{'\x04'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: newStorageKey,
|
||||
NodeValue: newStorageLeafNode,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Path: []byte{'\x0c'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.Account2LeafKey,
|
||||
NodeValue: account2AtBlock3LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
arguments := test.startingArguments
|
||||
diff, err := builder.BuildStateDiff(arguments.oldStateRoot, arguments.newStateRoot, arguments.blockNumber, arguments.blockHash)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
receivedStateDiffRlp, err := rlp.EncodeToBytes(diff)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
expectedStateDiffRlp, err := rlp.EncodeToBytes(test.expected)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
sort.Slice(receivedStateDiffRlp, func(i, j int) bool { return receivedStateDiffRlp[i] < receivedStateDiffRlp[j] })
|
||||
sort.Slice(expectedStateDiffRlp, func(i, j int) bool { return expectedStateDiffRlp[i] < expectedStateDiffRlp[j] })
|
||||
if !bytes.Equal(receivedStateDiffRlp, expectedStateDiffRlp) {
|
||||
t.Logf("Test failed: %s", test.name)
|
||||
t.Errorf("actual state diff: %+v\r\n\r\n\r\nexpected state diff: %+v", diff, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuilderWithWatchedAddressList(t *testing.T) {
|
||||
blockHashes, blockMap, chain := testhelpers.MakeChain(3, testhelpers.Genesis)
|
||||
contractLeafKey = testhelpers.AddressToLeafKey(testhelpers.ContractAddr)
|
||||
defer chain.Stop()
|
||||
block0 = blockMap[blockHashes[3]]
|
||||
block1 = blockMap[blockHashes[2]]
|
||||
block2 = blockMap[blockHashes[1]]
|
||||
block3 = blockMap[blockHashes[0]]
|
||||
config := statediff.Config{
|
||||
LeafProofs: true,
|
||||
IntermediateNodes: false,
|
||||
WatchedAddresses: []string{testhelpers.Account1Addr.Hex(), testhelpers.ContractAddr.Hex()},
|
||||
}
|
||||
@ -460,12 +772,11 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
|
||||
BlockHash: block1.Hash(),
|
||||
CreatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: testhelpers.Account1LeafKey,
|
||||
NodeValue: account1AtBlock1LeafNode,
|
||||
Proof: [][]byte{{248, 113, 160, 87, 118, 82, 182, 37, 183, 123, 219, 91, 247, 123, 196, 63, 49, 37, 202, 215, 70, 77, 103, 157, 21, 117, 86, 82, 119, 211, 97, 27, 128, 83, 231, 128, 128, 128, 128, 160, 254, 136, 159, 16, 229, 219, 143, 44, 43, 243, 85, 146, 129, 82, 161, 127, 110, 59, 185, 154, 146, 65, 172, 109, 132, 199, 126, 98, 100, 80, 156, 121, 128, 128, 128, 128, 128, 128, 128, 128, 160, 17, 219, 12, 218, 52, 168, 150, 218, 190, 182, 131, 155, 176, 106, 56, 244, 149, 20, 207, 164, 134, 67, 89, 132, 235, 1, 59, 125, 249, 238, 133, 197, 128, 128},
|
||||
{248, 107, 160, 57, 38, 219, 105, 170, 206, 213, 24, 233, 185, 240, 244, 52, 164, 115, 231, 23, 65, 9, 201, 67, 84, 139, 184, 242, 59, 228, 28, 167, 109, 154, 210, 184, 72, 248, 70, 128, 130, 39, 16, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x0e'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.Account1LeafKey,
|
||||
NodeValue: account1AtBlock1LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||
@ -487,17 +798,16 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
|
||||
BlockHash: block2.Hash(),
|
||||
CreatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: contractLeafKey,
|
||||
NodeValue: contractAccountAtBlock2LeafNode,
|
||||
Proof: [][]byte{{248, 177, 160, 177, 155, 238, 178, 242, 47, 83, 2, 49, 141, 155, 92, 149, 175, 245, 120, 233, 177, 101, 67, 46, 200, 23, 250, 41, 74, 135, 94, 61, 133, 51, 162, 128, 128, 128, 128, 160, 179, 86, 53, 29, 96, 188, 152, 148, 207, 31, 29, 108, 182, 140, 129, 95, 1, 49, 213, 15, 29, 168, 60, 64, 35, 160, 158, 200, 85, 207, 255, 145, 160, 114, 57, 32, 11, 115, 232, 140, 238, 165, 222, 121, 226, 208, 2, 192, 216, 67, 198, 179, 31, 181, 27, 208, 243, 99, 202, 48, 148, 207, 107, 106, 177, 128, 128, 128, 128, 128, 160, 10, 173, 165, 125, 110, 240, 77, 112, 149, 100, 135, 237, 25, 228, 116, 7, 195, 9, 210, 166, 208, 148, 101, 23, 244, 238, 84, 84, 211, 249, 138, 137, 128, 160, 255, 115, 147, 190, 57, 135, 174, 188, 86, 51, 227, 70, 22, 253, 237, 49, 24, 19, 149, 199, 142, 195, 186, 244, 70, 51, 138, 0, 146, 148, 117, 60, 128, 128},
|
||||
{248, 105, 160, 49, 20, 101, 138, 116, 217, 204, 159, 122, 207, 44, 92, 214, 150, 195, 73, 77, 124, 52, 77, 120, 191, 236, 58, 221, 13, 145, 236, 78, 141, 28, 69, 184, 70, 248, 68, 1, 128, 160, 130, 30, 37, 86, 162, 144, 200, 100, 5, 248, 22, 10, 45, 102, 32, 66, 164, 49, 186, 69, 107, 157, 178, 101, 199, 155, 184, 55, 192, 75, 229, 240, 160, 117, 63, 152, 168, 212, 50, 139, 21, 99, 110, 70, 246, 111, 44, 180, 188, 134, 1, 0, 170, 23, 150, 124, 193, 69, 252, 209, 125, 29, 71, 16, 234}},
|
||||
Path: []byte{'\x06'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: contractLeafKey,
|
||||
NodeValue: contractAccountAtBlock2LeafNode,
|
||||
Storage: []statediff.StorageDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: originalStorageKey,
|
||||
NodeValue: originalStorageLeafNode,
|
||||
Proof: [][]byte{{227, 161, 32, 41, 13, 236, 217, 84, 139, 98, 168, 214, 3, 69, 169, 136, 56, 111, 200, 75, 166, 188, 149, 72, 64, 8, 246, 54, 47, 147, 22, 14, 243, 229, 99, 1}},
|
||||
Path: []byte{},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: originalStorageKey,
|
||||
NodeValue: originalStorageLeafNode,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -505,12 +815,11 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
|
||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||
UpdatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: testhelpers.Account1LeafKey,
|
||||
NodeValue: account1AtBlock2LeafNode,
|
||||
Proof: [][]byte{{248, 177, 160, 177, 155, 238, 178, 242, 47, 83, 2, 49, 141, 155, 92, 149, 175, 245, 120, 233, 177, 101, 67, 46, 200, 23, 250, 41, 74, 135, 94, 61, 133, 51, 162, 128, 128, 128, 128, 160, 179, 86, 53, 29, 96, 188, 152, 148, 207, 31, 29, 108, 182, 140, 129, 95, 1, 49, 213, 15, 29, 168, 60, 64, 35, 160, 158, 200, 85, 207, 255, 145, 160, 114, 57, 32, 11, 115, 232, 140, 238, 165, 222, 121, 226, 208, 2, 192, 216, 67, 198, 179, 31, 181, 27, 208, 243, 99, 202, 48, 148, 207, 107, 106, 177, 128, 128, 128, 128, 128, 160, 10, 173, 165, 125, 110, 240, 77, 112, 149, 100, 135, 237, 25, 228, 116, 7, 195, 9, 210, 166, 208, 148, 101, 23, 244, 238, 84, 84, 211, 249, 138, 137, 128, 160, 255, 115, 147, 190, 57, 135, 174, 188, 86, 51, 227, 70, 22, 253, 237, 49, 24, 19, 149, 199, 142, 195, 186, 244, 70, 51, 138, 0, 146, 148, 117, 60, 128, 128},
|
||||
{248, 107, 160, 57, 38, 219, 105, 170, 206, 213, 24, 233, 185, 240, 244, 52, 164, 115, 231, 23, 65, 9, 201, 67, 84, 139, 184, 242, 59, 228, 28, 167, 109, 154, 210, 184, 72, 248, 70, 2, 130, 39, 16, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x0e'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.Account1LeafKey,
|
||||
NodeValue: account1AtBlock2LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -532,18 +841,22 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
|
||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||
UpdatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: contractLeafKey,
|
||||
NodeValue: contractAccountAtBlock3LeafNode,
|
||||
Proof: [][]byte{{248, 177, 160, 101, 223, 138, 81, 34, 40, 229, 170, 198, 188, 136, 99, 7, 55, 33, 112, 160, 111, 181, 131, 167, 201, 131, 24, 201, 211, 177, 30, 159, 229, 246, 6, 128, 128, 128, 128, 160, 179, 86, 53, 29, 96, 188, 152, 148, 207, 31, 29, 108, 182, 140, 129, 95, 1, 49, 213, 15, 29, 168, 60, 64, 35, 160, 158, 200, 85, 207, 255, 145, 160, 32, 135, 108, 213, 150, 150, 110, 44, 170, 65, 75, 154, 74, 249, 94, 65, 74, 107, 100, 115, 39, 5, 3, 26, 22, 238, 138, 114, 254, 21, 6, 171, 128, 128, 128, 128, 128, 160, 4, 228, 121, 222, 255, 218, 60, 247, 15, 0, 34, 198, 28, 229, 180, 129, 109, 157, 68, 181, 248, 229, 200, 123, 29, 81, 145, 114, 90, 209, 205, 210, 128, 160, 255, 115, 147, 190, 57, 135, 174, 188, 86, 51, 227, 70, 22, 253, 237, 49, 24, 19, 149, 199, 142, 195, 186, 244, 70, 51, 138, 0, 146, 148, 117, 60, 128, 128},
|
||||
{248, 105, 160, 49, 20, 101, 138, 116, 217, 204, 159, 122, 207, 44, 92, 214, 150, 195, 73, 77, 124, 52, 77, 120, 191, 236, 58, 221, 13, 145, 236, 78, 141, 28, 69, 184, 70, 248, 68, 1, 128, 160, 113, 224, 209, 75, 43, 147, 229, 199, 249, 116, 142, 105, 225, 254, 95, 23, 73, 138, 28, 58, 195, 206, 194, 159, 150, 175, 19, 215, 248, 164, 224, 112, 160, 117, 63, 152, 168, 212, 50, 139, 21, 99, 110, 70, 246, 111, 44, 180, 188, 134, 1, 0, 170, 23, 150, 124, 193, 69, 252, 209, 125, 29, 71, 16, 234}},
|
||||
Path: []byte{'\x06'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: contractLeafKey,
|
||||
NodeValue: contractAccountAtBlock3LeafNode,
|
||||
Storage: []statediff.StorageDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: updatedStorageKey,
|
||||
NodeValue: updatedStorageLeafNode,
|
||||
Proof: [][]byte{{248, 81, 128, 128, 160, 79, 197, 241, 58, 178, 249, 186, 12, 45, 168, 139, 1, 81, 171, 14, 124, 244, 216, 93, 8, 204, 164, 92, 205, 146, 60, 106, 183, 99, 35, 235, 40, 128, 160, 205, 69, 114, 89, 105, 97, 21, 35, 94, 100, 199, 130, 35, 52, 214, 33, 41, 226, 241, 96, 68, 37, 167, 218, 100, 148, 243, 95, 196, 91, 229, 24, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128},
|
||||
{226, 160, 48, 87, 135, 250, 18, 168, 35, 224, 242, 183, 99, 28, 196, 27, 59, 168, 130, 139, 51, 33, 202, 129, 17, 17, 250, 117, 205, 58, 163, 187, 90, 206, 3}},
|
||||
Path: []byte{'\x02'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: originalStorageKey,
|
||||
NodeValue: updatedStorageLeafNode,
|
||||
},
|
||||
{
|
||||
Path: []byte{'\x04'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: newStorageKey,
|
||||
NodeValue: newStorageLeafNode,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -570,7 +883,7 @@ func TestBuilderWithWatchedAddressList(t *testing.T) {
|
||||
sort.Slice(expectedStateDiffRlp, func(i, j int) bool { return expectedStateDiffRlp[i] < expectedStateDiffRlp[j] })
|
||||
if !bytes.Equal(receivedStateDiffRlp, expectedStateDiffRlp) {
|
||||
t.Logf("Test failed: %s", test.name)
|
||||
t.Errorf("actual state diff rlp: %+v\nexpected state diff rlp: %+v", receivedStateDiffRlp, expectedStateDiffRlp)
|
||||
t.Errorf("actual state diff: %+v\nexpected state diff: %+v", diff, test.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,6 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
)
|
||||
|
||||
func sortKeys(data AccountsMap) []string {
|
||||
@ -38,22 +35,6 @@ func sortKeys(data AccountsMap) []string {
|
||||
return keys
|
||||
}
|
||||
|
||||
// bytesToNiblePath converts the byte representation of a path to its string representation
|
||||
func bytesToNiblePath(path []byte) string {
|
||||
if hasTerm(path) {
|
||||
path = path[:len(path)-1]
|
||||
}
|
||||
nibblePath := ""
|
||||
for i, v := range common.ToHex(path) {
|
||||
if i%2 == 0 && i > 1 {
|
||||
continue
|
||||
}
|
||||
nibblePath = nibblePath + string(v)
|
||||
}
|
||||
|
||||
return nibblePath
|
||||
}
|
||||
|
||||
// findIntersection finds the set of strings from both arrays that are equivalent (same key as same index)
|
||||
// this is used to find which keys have been both "deleted" and "created" i.e. they were updated
|
||||
func findIntersection(a, b []string) []string {
|
||||
@ -91,16 +72,6 @@ func findIntersection(a, b []string) []string {
|
||||
|
||||
}
|
||||
|
||||
// pathToStr converts the NodeIterator path to a string representation
|
||||
func pathToStr(it trie.NodeIterator) string {
|
||||
return bytesToNiblePath(it.Path())
|
||||
}
|
||||
|
||||
// hasTerm returns whether a hex key has the terminator flag.
|
||||
func hasTerm(s []byte) bool {
|
||||
return len(s) > 0 && s[len(s)-1] == 16
|
||||
}
|
||||
|
||||
// CheckKeyType checks what type of key we have
|
||||
func CheckKeyType(elements []interface{}) (NodeType, error) {
|
||||
if len(elements) > 2 {
|
||||
|
@ -34,7 +34,7 @@ import (
|
||||
|
||||
var (
|
||||
block0, block1 *types.Block
|
||||
burnLeafKey = testhelpers.AddressToEncodedPath(common.HexToAddress("0x0"))
|
||||
burnLeafKey = testhelpers.AddressToLeafKey(common.HexToAddress("0x0"))
|
||||
emptyAccountDiffEventualMap = make([]statediff.AccountDiff, 0)
|
||||
account1, _ = rlp.EncodeToBytes(state.Account{
|
||||
Nonce: uint64(0),
|
||||
@ -92,31 +92,28 @@ func testSubscriptionAPI(t *testing.T) {
|
||||
BlockHash: block1.Hash(),
|
||||
CreatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: burnLeafKey,
|
||||
NodeValue: burnAccount1LeafNode,
|
||||
Proof: [][]byte{{248, 113, 160, 87, 118, 82, 182, 37, 183, 123, 219, 91, 247, 123, 196, 63, 49, 37, 202, 215, 70, 77, 103, 157, 21, 117, 86, 82, 119, 211, 97, 27, 128, 83, 231, 128, 128, 128, 128, 160, 254, 136, 159, 16, 229, 219, 143, 44, 43, 243, 85, 146, 129, 82, 161, 127, 110, 59, 185, 154, 146, 65, 172, 109, 132, 199, 126, 98, 100, 80, 156, 121, 128, 128, 128, 128, 128, 128, 128, 128, 160, 17, 219, 12, 218, 52, 168, 150, 218, 190, 182, 131, 155, 176, 106, 56, 244, 149, 20, 207, 164, 134, 67, 89, 132, 235, 1, 59, 125, 249, 238, 133, 197, 128, 128},
|
||||
{248, 113, 160, 51, 128, 199, 183, 174, 129, 165, 142, 185, 141, 156, 120, 222, 74, 31, 215, 253, 149, 53, 252, 149, 62, 210, 190, 96, 45, 170, 164, 23, 103, 49, 42, 184, 78, 248, 76, 128, 136, 27, 193, 109, 103, 78, 200, 0, 0, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x05'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: burnLeafKey,
|
||||
NodeValue: burnAccount1LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: testhelpers.Account1LeafKey,
|
||||
NodeValue: account1LeafNode,
|
||||
Proof: [][]byte{{248, 113, 160, 87, 118, 82, 182, 37, 183, 123, 219, 91, 247, 123, 196, 63, 49, 37, 202, 215, 70, 77, 103, 157, 21, 117, 86, 82, 119, 211, 97, 27, 128, 83, 231, 128, 128, 128, 128, 160, 254, 136, 159, 16, 229, 219, 143, 44, 43, 243, 85, 146, 129, 82, 161, 127, 110, 59, 185, 154, 146, 65, 172, 109, 132, 199, 126, 98, 100, 80, 156, 121, 128, 128, 128, 128, 128, 128, 128, 128, 160, 17, 219, 12, 218, 52, 168, 150, 218, 190, 182, 131, 155, 176, 106, 56, 244, 149, 20, 207, 164, 134, 67, 89, 132, 235, 1, 59, 125, 249, 238, 133, 197, 128, 128},
|
||||
{248, 107, 160, 57, 38, 219, 105, 170, 206, 213, 24, 233, 185, 240, 244, 52, 164, 115, 231, 23, 65, 9, 201, 67, 84, 139, 184, 242, 59, 228, 28, 167, 109, 154, 210, 184, 72, 248, 70, 128, 130, 39, 16, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x0e'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.Account1LeafKey,
|
||||
NodeValue: account1LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||
UpdatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: testhelpers.BankLeafKey,
|
||||
NodeValue: bankAccount1LeafNode,
|
||||
Proof: [][]byte{{248, 113, 160, 87, 118, 82, 182, 37, 183, 123, 219, 91, 247, 123, 196, 63, 49, 37, 202, 215, 70, 77, 103, 157, 21, 117, 86, 82, 119, 211, 97, 27, 128, 83, 231, 128, 128, 128, 128, 160, 254, 136, 159, 16, 229, 219, 143, 44, 43, 243, 85, 146, 129, 82, 161, 127, 110, 59, 185, 154, 146, 65, 172, 109, 132, 199, 126, 98, 100, 80, 156, 121, 128, 128, 128, 128, 128, 128, 128, 128, 160, 17, 219, 12, 218, 52, 168, 150, 218, 190, 182, 131, 155, 176, 106, 56, 244, 149, 20, 207, 164, 134, 67, 89, 132, 235, 1, 59, 125, 249, 238, 133, 197, 128, 128},
|
||||
{248, 109, 160, 48, 191, 73, 244, 64, 161, 205, 5, 39, 228, 208, 110, 39, 101, 101, 76, 15, 86, 69, 34, 87, 81, 109, 121, 58, 155, 141, 96, 77, 207, 223, 42, 184, 74, 248, 72, 1, 132, 5, 245, 185, 240, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x00'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.BankLeafKey,
|
||||
NodeValue: bankAccount1LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -125,7 +122,6 @@ func testSubscriptionAPI(t *testing.T) {
|
||||
parentBlockChain := make(chan *types.Block)
|
||||
serviceQuitChan := make(chan bool)
|
||||
config := statediff.Config{
|
||||
LeafProofs: true,
|
||||
IntermediateNodes: false,
|
||||
}
|
||||
mockBlockChain := &BlockChain{}
|
||||
@ -188,37 +184,33 @@ func testHTTPAPI(t *testing.T) {
|
||||
BlockHash: block1.Hash(),
|
||||
CreatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: burnLeafKey,
|
||||
NodeValue: burnAccount1LeafNode,
|
||||
Proof: [][]byte{{248, 113, 160, 87, 118, 82, 182, 37, 183, 123, 219, 91, 247, 123, 196, 63, 49, 37, 202, 215, 70, 77, 103, 157, 21, 117, 86, 82, 119, 211, 97, 27, 128, 83, 231, 128, 128, 128, 128, 160, 254, 136, 159, 16, 229, 219, 143, 44, 43, 243, 85, 146, 129, 82, 161, 127, 110, 59, 185, 154, 146, 65, 172, 109, 132, 199, 126, 98, 100, 80, 156, 121, 128, 128, 128, 128, 128, 128, 128, 128, 160, 17, 219, 12, 218, 52, 168, 150, 218, 190, 182, 131, 155, 176, 106, 56, 244, 149, 20, 207, 164, 134, 67, 89, 132, 235, 1, 59, 125, 249, 238, 133, 197, 128, 128},
|
||||
{248, 113, 160, 51, 128, 199, 183, 174, 129, 165, 142, 185, 141, 156, 120, 222, 74, 31, 215, 253, 149, 53, 252, 149, 62, 210, 190, 96, 45, 170, 164, 23, 103, 49, 42, 184, 78, 248, 76, 128, 136, 27, 193, 109, 103, 78, 200, 0, 0, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x05'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: burnLeafKey,
|
||||
NodeValue: burnAccount1LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: testhelpers.Account1LeafKey,
|
||||
NodeValue: account1LeafNode,
|
||||
Proof: [][]byte{{248, 113, 160, 87, 118, 82, 182, 37, 183, 123, 219, 91, 247, 123, 196, 63, 49, 37, 202, 215, 70, 77, 103, 157, 21, 117, 86, 82, 119, 211, 97, 27, 128, 83, 231, 128, 128, 128, 128, 160, 254, 136, 159, 16, 229, 219, 143, 44, 43, 243, 85, 146, 129, 82, 161, 127, 110, 59, 185, 154, 146, 65, 172, 109, 132, 199, 126, 98, 100, 80, 156, 121, 128, 128, 128, 128, 128, 128, 128, 128, 160, 17, 219, 12, 218, 52, 168, 150, 218, 190, 182, 131, 155, 176, 106, 56, 244, 149, 20, 207, 164, 134, 67, 89, 132, 235, 1, 59, 125, 249, 238, 133, 197, 128, 128},
|
||||
{248, 107, 160, 57, 38, 219, 105, 170, 206, 213, 24, 233, 185, 240, 244, 52, 164, 115, 231, 23, 65, 9, 201, 67, 84, 139, 184, 242, 59, 228, 28, 167, 109, 154, 210, 184, 72, 248, 70, 128, 130, 39, 16, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x0e'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.Account1LeafKey,
|
||||
NodeValue: account1LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
DeletedAccounts: emptyAccountDiffEventualMap,
|
||||
UpdatedAccounts: []statediff.AccountDiff{
|
||||
{
|
||||
NodeType: statediff.Leaf,
|
||||
EncodedPath: testhelpers.BankLeafKey,
|
||||
NodeValue: bankAccount1LeafNode,
|
||||
Proof: [][]byte{{248, 113, 160, 87, 118, 82, 182, 37, 183, 123, 219, 91, 247, 123, 196, 63, 49, 37, 202, 215, 70, 77, 103, 157, 21, 117, 86, 82, 119, 211, 97, 27, 128, 83, 231, 128, 128, 128, 128, 160, 254, 136, 159, 16, 229, 219, 143, 44, 43, 243, 85, 146, 129, 82, 161, 127, 110, 59, 185, 154, 146, 65, 172, 109, 132, 199, 126, 98, 100, 80, 156, 121, 128, 128, 128, 128, 128, 128, 128, 128, 160, 17, 219, 12, 218, 52, 168, 150, 218, 190, 182, 131, 155, 176, 106, 56, 244, 149, 20, 207, 164, 134, 67, 89, 132, 235, 1, 59, 125, 249, 238, 133, 197, 128, 128},
|
||||
{248, 109, 160, 48, 191, 73, 244, 64, 161, 205, 5, 39, 228, 208, 110, 39, 101, 101, 76, 15, 86, 69, 34, 87, 81, 109, 121, 58, 155, 141, 96, 77, 207, 223, 42, 184, 74, 248, 72, 1, 132, 5, 245, 185, 240, 160, 86, 232, 31, 23, 27, 204, 85, 166, 255, 131, 69, 230, 146, 192, 248, 110, 91, 72, 224, 27, 153, 108, 173, 192, 1, 98, 47, 181, 227, 99, 180, 33, 160, 197, 210, 70, 1, 134, 247, 35, 60, 146, 126, 125, 178, 220, 199, 3, 192, 229, 0, 182, 83, 202, 130, 39, 59, 123, 250, 216, 4, 93, 133, 164, 112}},
|
||||
Storage: []statediff.StorageDiff{},
|
||||
Path: []byte{'\x00'},
|
||||
NodeType: statediff.Leaf,
|
||||
LeafKey: testhelpers.BankLeafKey,
|
||||
NodeValue: bankAccount1LeafNode,
|
||||
Storage: []statediff.StorageDiff{},
|
||||
},
|
||||
},
|
||||
}
|
||||
expectedStateDiffBytes, _ := rlp.EncodeToBytes(expectedStateDiff)
|
||||
config := statediff.Config{
|
||||
LeafProofs: true,
|
||||
IntermediateNodes: false,
|
||||
}
|
||||
mockBlockChain := &BlockChain{}
|
||||
|
@ -51,7 +51,7 @@ var (
|
||||
Testdb = rawdb.NewMemoryDatabase()
|
||||
TestBankKey, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||
TestBankAddress = crypto.PubkeyToAddress(TestBankKey.PublicKey) //0x71562b71999873DB5b286dF957af199Ec94617F7
|
||||
BankLeafKey = AddressToEncodedPath(TestBankAddress)
|
||||
BankLeafKey = AddressToLeafKey(TestBankAddress)
|
||||
TestBankFunds = big.NewInt(100000000)
|
||||
Genesis = core.GenesisBlockForTesting(Testdb, TestBankAddress, TestBankFunds)
|
||||
|
||||
@ -59,8 +59,8 @@ var (
|
||||
Account2Key, _ = crypto.HexToECDSA("49a7b37aa6f6645917e7b807e9d1c00d4fa71f18343b0d4122a4d2df64dd6fee")
|
||||
Account1Addr = crypto.PubkeyToAddress(Account1Key.PublicKey) //0x703c4b2bD70c169f5717101CaeE543299Fc946C7
|
||||
Account2Addr = crypto.PubkeyToAddress(Account2Key.PublicKey) //0x0D3ab14BBaD3D99F4203bd7a11aCB94882050E7e
|
||||
Account1LeafKey = AddressToEncodedPath(Account1Addr)
|
||||
Account2LeafKey = AddressToEncodedPath(Account2Addr)
|
||||
Account1LeafKey = AddressToLeafKey(Account1Addr)
|
||||
Account2LeafKey = AddressToLeafKey(Account2Addr)
|
||||
ContractCode = common.Hex2Bytes("608060405234801561001057600080fd5b50602060405190810160405280600160ff16815250600090600161003592919061003b565b506100a5565b826064810192821561006f579160200282015b8281111561006e578251829060ff1690559160200191906001019061004e565b5b50905061007c9190610080565b5090565b6100a291905b8082111561009e576000816000905550600101610086565b5090565b90565b610124806100b46000396000f3fe6080604052348015600f57600080fd5b5060043610604f576000357c01000000000000000000000000000000000000000000000000000000009004806360cd2685146054578063c16431b9146093575b600080fd5b607d60048036036020811015606857600080fd5b810190808035906020019092919050505060c8565b6040518082815260200191505060405180910390f35b60c66004803603604081101560a757600080fd5b81019080803590602001909291908035906020019092919050505060e0565b005b6000808260648110151560d757fe5b01549050919050565b8060008360648110151560ef57fe5b0181905550505056fea165627a7a7230582064e918c3140a117bf3aa65865a9b9e83fae21ad1720506e7933b2a9f54bb40260029")
|
||||
ContractAddr common.Address
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user