mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-31 03:06:44 +00:00

* [DEV-378] Added feeAccumulator structures * [DEV-378] Added logic to create and store fee data when validating a block * [DEV-378] Renamed feeAccumulator to compactFeeData, and all related entities accordingly * [DEV-378] Converted MsgTx.TxHash() to pointer to hash and not hash * [DEV-378] Restructured parameters to buildFeeTransaction and related entities * [DEV-378] Finished the code that calculates fees for blocks * [DEV-378] Fix TxIndex after changing the structure of AcceptedTxsData * [DEV-378] For genesis block: Return empty AcceptedTxsData instead of nil * [DEV-378] Off-by-one error * [DEV-378] Length of compactFeeData should be determined by specific method, not * [DEV-378] Multiple bugfixes in tx fee calculation * [DEV-378] Calculate fee even if fastAdd, to save feeData * [DEV-378] use IsEqual instead of == when comparing TxHash * [DEV-378] txindex: if including block is the new block - don't fetch id from DB * [DEV-378] Fixed a few typos and made some vars consts * [DEV-378] Re-organized fee functions, removed redundant functions and constants, and revised a few comments * [DEV-378] Recovered fmt string changes lost in merge * [DEV-378] Renamed acceptedTxsData and related types and vars to txsAcceptanceData * [DEV-378] Some comment fixes * [DEV-378] Remove redundant .ToString()
61 lines
1.4 KiB
Go
61 lines
1.4 KiB
Go
package blockdag
|
|
|
|
import (
|
|
"io"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestFeeAccumulators(t *testing.T) {
|
|
fees := []uint64{1, 2, 3, 4, 5, 6, 7, 0xffffffffffffffff}
|
|
|
|
factory := newCompactFeeFactory()
|
|
|
|
for _, fee := range fees {
|
|
err := factory.add(fee)
|
|
if err != nil {
|
|
t.Fatalf("Error writing %d as tx fee: %s", fee, err)
|
|
}
|
|
}
|
|
|
|
expectedData := compactFeeData{
|
|
1, 0, 0, 0, 0, 0, 0, 0,
|
|
2, 0, 0, 0, 0, 0, 0, 0,
|
|
3, 0, 0, 0, 0, 0, 0, 0,
|
|
4, 0, 0, 0, 0, 0, 0, 0,
|
|
5, 0, 0, 0, 0, 0, 0, 0,
|
|
6, 0, 0, 0, 0, 0, 0, 0,
|
|
7, 0, 0, 0, 0, 0, 0, 0,
|
|
255, 255, 255, 255, 255, 255, 255, 255,
|
|
}
|
|
actualData, err := factory.data()
|
|
|
|
if err != nil {
|
|
t.Fatalf("Error getting bytes from writer: %s", err)
|
|
}
|
|
if !reflect.DeepEqual(expectedData, actualData) {
|
|
t.Errorf("Expected bytes: %v, but got: %v", expectedData, actualData)
|
|
}
|
|
|
|
iterator := actualData.iterator()
|
|
|
|
for i, expectedFee := range fees {
|
|
actualFee, err := iterator.next()
|
|
if err != nil {
|
|
t.Fatalf("Error getting fee for Tx#%d: %s", i, err)
|
|
}
|
|
|
|
if actualFee != expectedFee {
|
|
t.Errorf("Tx #%d: Expected fee: %d, but got %d", i, expectedFee, actualFee)
|
|
}
|
|
}
|
|
|
|
_, err = iterator.next()
|
|
if err == nil {
|
|
t.Fatal("No error from iterator.nextTxFee after done reading all transactions")
|
|
}
|
|
if err != io.EOF {
|
|
t.Fatalf("Error from iterator.nextTxFee after done reading all transactions is not io.EOF: %s", err)
|
|
}
|
|
}
|