(t *testing.T)
| 9 | ) |
| 10 | |
| 11 | func TestAddTransactionFeeOrdering(t *testing.T) { |
| 12 | // pre-define a mempool with the default config |
| 13 | mempool := NewMempool(DefaultMempoolConfig()) |
| 14 | // pre-define a test message |
| 15 | sig := &Signature{ |
| 16 | PublicKey: newTestPublicKeyBytes(t), |
| 17 | Signature: newTestPublicKeyBytes(t), |
| 18 | } |
| 19 | // pre-define an any for testing |
| 20 | a, e := NewAny(sig) |
| 21 | require.NoError(t, e) |
| 22 | // add a transaction |
| 23 | err := mempool.AddTransactions(func() []byte { |
| 24 | bz, err := Marshal(&Transaction{MessageType: testMessageName, Msg: a, Signature: sig, CreatedHeight: 1, |
| 25 | Time: uint64(time.Now().UnixMicro()), Fee: 1000, NetworkId: 1, ChainId: 2}) |
| 26 | require.NoError(t, err) |
| 27 | return bz |
| 28 | }()) |
| 29 | require.NoError(t, err) |
| 30 | // add another transaction with the same fee |
| 31 | err = mempool.AddTransactions(func() []byte { |
| 32 | bz, err := Marshal(&Transaction{MessageType: testMessageName, Msg: a, Signature: sig, CreatedHeight: 1, |
| 33 | Time: uint64(time.Now().UnixMicro()), Fee: 1000, NetworkId: 1, ChainId: 3}) |
| 34 | require.NoError(t, err) |
| 35 | return bz |
| 36 | }()) |
| 37 | require.NoError(t, err) |
| 38 | // add another transaction with a higher fee |
| 39 | err = mempool.AddTransactions(func() []byte { |
| 40 | bz, err := Marshal(&Transaction{MessageType: testMessageName, Msg: a, Signature: sig, CreatedHeight: 1, |
| 41 | Time: uint64(time.Now().UnixMicro()), Fee: 1001, NetworkId: 1, ChainId: 1}) |
| 42 | require.NoError(t, err) |
| 43 | return bz |
| 44 | }()) |
| 45 | require.NoError(t, err) |
| 46 | // add another transaction with the lowest fee |
| 47 | err = mempool.AddTransactions(func() []byte { |
| 48 | bz, err := Marshal(&Transaction{MessageType: testMessageName, Msg: a, Signature: sig, CreatedHeight: 1, |
| 49 | Time: uint64(time.Now().UnixMicro()), Fee: 1, NetworkId: 1, ChainId: 5}) |
| 50 | require.NoError(t, err) |
| 51 | return bz |
| 52 | }()) |
| 53 | require.NoError(t, err) |
| 54 | // add another transaction with the same fee |
| 55 | err = mempool.AddTransactions(func() []byte { |
| 56 | bz, err := Marshal(&Transaction{MessageType: testMessageName, Msg: a, Signature: sig, CreatedHeight: 1, |
| 57 | Time: uint64(time.Now().UnixMicro()), Fee: 1000, NetworkId: 1, ChainId: 4}) |
| 58 | require.NoError(t, err) |
| 59 | return bz |
| 60 | }()) |
| 61 | require.NoError(t, err) |
| 62 | it := mempool.Iterator() |
| 63 | defer it.Close() |
| 64 | // iterate through each |
| 65 | for expected := 1; it.Valid(); it.Next() { |
| 66 | tx := new(Transaction) |
| 67 | require.NoError(t, Unmarshal(it.Key(), tx)) |
| 68 | // compare got vs expected |
nothing calls this directly
no test coverage detected