Skip to content

Commit a945cb1

Browse files
committed
fix rct unit tests
1 parent bbfaea9 commit a945cb1

File tree

1 file changed

+46
-10
lines changed

1 file changed

+46
-10
lines changed

statediff/indexer/indexer_test.go

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ var (
4949
mockBlock *types.Block
5050
headerCID, trx1CID, trx2CID, trx3CID, trx4CID, trx5CID cid.Cid
5151
rct1CID, rct2CID, rct3CID, rct4CID, rct5CID cid.Cid
52+
rctLeaf1, rctLeaf2, rctLeaf3, rctLeaf4, rctLeaf5 []byte
5253
state1CID, state2CID, storageCID cid.Cid
5354
)
5455

@@ -124,14 +125,49 @@ func init() {
124125
trx3CID, _ = ipld.RawdataToCid(ipld.MEthTx, tx3, multihash.KECCAK_256)
125126
trx4CID, _ = ipld.RawdataToCid(ipld.MEthTx, tx4, multihash.KECCAK_256)
126127
trx5CID, _ = ipld.RawdataToCid(ipld.MEthTx, tx5, multihash.KECCAK_256)
127-
rct1CID, _ = ipld.RawdataToCid(ipld.MEthTxReceipt, rct1, multihash.KECCAK_256)
128-
rct2CID, _ = ipld.RawdataToCid(ipld.MEthTxReceipt, rct2, multihash.KECCAK_256)
129-
rct3CID, _ = ipld.RawdataToCid(ipld.MEthTxReceipt, rct3, multihash.KECCAK_256)
130-
rct4CID, _ = ipld.RawdataToCid(ipld.MEthTxReceipt, rct4, multihash.KECCAK_256)
131-
rct5CID, _ = ipld.RawdataToCid(ipld.MEthTxReceipt, rct5, multihash.KECCAK_256)
128+
/*
129+
rct1Node, _ := ipld.NewReceipt(rcts[0])
130+
rct2Node, _ := ipld.NewReceipt(rcts[1])
131+
rct3Node, _ := ipld.NewReceipt(rcts[2])
132+
rct4Node, _ := ipld.NewReceipt(rcts[3])
133+
rct5Node, _ := ipld.NewReceipt(rcts[4])
134+
*/
132135
state1CID, _ = ipld.RawdataToCid(ipld.MEthStateTrie, mocks.ContractLeafNode, multihash.KECCAK_256)
133136
state2CID, _ = ipld.RawdataToCid(ipld.MEthStateTrie, mocks.AccountLeafNode, multihash.KECCAK_256)
134137
storageCID, _ = ipld.RawdataToCid(ipld.MEthStorageTrie, mocks.StorageLeafNode, multihash.KECCAK_256)
138+
139+
receiptTrie := ipld.NewRctTrie()
140+
141+
receiptTrie.Add(0, rct1)
142+
receiptTrie.Add(1, rct2)
143+
receiptTrie.Add(2, rct3)
144+
receiptTrie.Add(3, rct4)
145+
receiptTrie.Add(4, rct5)
146+
147+
rctLeafNodes, keys, _ := receiptTrie.GetLeafNodes()
148+
149+
rctleafNodeCids := make([]cid.Cid, len(rctLeafNodes))
150+
orderedRctLeafNodes := make([][]byte, len(rctLeafNodes))
151+
for i, rln := range rctLeafNodes {
152+
var idx uint
153+
154+
r := bytes.NewReader(keys[i].TrieKey)
155+
rlp.Decode(r, &idx)
156+
rctleafNodeCids[idx] = rln.Cid()
157+
orderedRctLeafNodes[idx] = rln.RawData()
158+
}
159+
160+
rct1CID = rctleafNodeCids[0]
161+
rct2CID = rctleafNodeCids[1]
162+
rct3CID = rctleafNodeCids[2]
163+
rct4CID = rctleafNodeCids[3]
164+
rct5CID = rctleafNodeCids[4]
165+
166+
rctLeaf1 = orderedRctLeafNodes[0]
167+
rctLeaf2 = orderedRctLeafNodes[1]
168+
rctLeaf3 = orderedRctLeafNodes[2]
169+
rctLeaf4 = orderedRctLeafNodes[3]
170+
rctLeaf5 = orderedRctLeafNodes[4]
135171
}
136172

137173
func setup(t *testing.T) {
@@ -416,7 +452,7 @@ func TestPublishAndIndexer(t *testing.T) {
416452

417453
switch c {
418454
case rct1CID.String():
419-
shared.ExpectEqual(t, data, rct1)
455+
shared.ExpectEqual(t, data, rctLeaf1)
420456
var postStatus uint64
421457
pgStr = `SELECT post_status FROM eth.receipt_cids WHERE leaf_cid = $1`
422458
err = db.Get(&postStatus, pgStr, c)
@@ -425,7 +461,7 @@ func TestPublishAndIndexer(t *testing.T) {
425461
}
426462
shared.ExpectEqual(t, postStatus, mocks.ExpectedPostStatus)
427463
case rct2CID.String():
428-
shared.ExpectEqual(t, data, rct2)
464+
shared.ExpectEqual(t, data, rctLeaf2)
429465
var postState string
430466
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
431467
err = db.Get(&postState, pgStr, c)
@@ -434,7 +470,7 @@ func TestPublishAndIndexer(t *testing.T) {
434470
}
435471
shared.ExpectEqual(t, postState, mocks.ExpectedPostState1)
436472
case rct3CID.String():
437-
shared.ExpectEqual(t, data, rct3)
473+
shared.ExpectEqual(t, data, rctLeaf3)
438474
var postState string
439475
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
440476
err = db.Get(&postState, pgStr, c)
@@ -443,7 +479,7 @@ func TestPublishAndIndexer(t *testing.T) {
443479
}
444480
shared.ExpectEqual(t, postState, mocks.ExpectedPostState2)
445481
case rct4CID.String():
446-
shared.ExpectEqual(t, data, rct4)
482+
shared.ExpectEqual(t, data, rctLeaf4)
447483
var postState string
448484
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
449485
err = db.Get(&postState, pgStr, c)
@@ -452,7 +488,7 @@ func TestPublishAndIndexer(t *testing.T) {
452488
}
453489
shared.ExpectEqual(t, postState, mocks.ExpectedPostState3)
454490
case rct5CID.String():
455-
shared.ExpectEqual(t, data, rct5)
491+
shared.ExpectEqual(t, data, rctLeaf5)
456492
var postState string
457493
pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1`
458494
err = db.Get(&postState, pgStr, c)

0 commit comments

Comments
 (0)