(t *testing.T)
| 72 | } |
| 73 | |
| 74 | func TestAddTransaction(t *testing.T) { |
| 75 | // pre-define a test message |
| 76 | sig := &Signature{ |
| 77 | PublicKey: newTestPublicKeyBytes(t), |
| 78 | Signature: newTestPublicKeyBytes(t), |
| 79 | } |
| 80 | // pre-define an any for testing |
| 81 | a, e := NewAny(sig) |
| 82 | require.NoError(t, e) |
| 83 | // pre-define a transaction to add |
| 84 | tx := &Transaction{MessageType: testMessageName, Msg: a, Signature: sig, CreatedHeight: 1, |
| 85 | Time: uint64(time.Now().UnixMicro()), Fee: 1000, NetworkId: 1, ChainId: 2} |
| 86 | // marshal to bytes |
| 87 | transaction, err := Marshal(tx) |
| 88 | require.NoError(t, err) |
| 89 | tests := []struct { |
| 90 | name string |
| 91 | detail string |
| 92 | mempool FeeMempool |
| 93 | toAdd []byte |
| 94 | // expected |
| 95 | transactions [][]byte |
| 96 | count int |
| 97 | error string |
| 98 | }{ |
| 99 | { |
| 100 | name: "max tx size", |
| 101 | detail: "the tx size exceeds max (config)", |
| 102 | mempool: FeeMempool{}, |
| 103 | toAdd: transaction, |
| 104 | error: "max tx size", |
| 105 | }, |
| 106 | { |
| 107 | name: "already exists", |
| 108 | detail: "transaction not added because it already exists", |
| 109 | mempool: FeeMempool{ |
| 110 | pool: MempoolTxs{ |
| 111 | m: map[string]struct{}{crypto.HashString(transaction): {}}, |
| 112 | }, |
| 113 | config: MempoolConfig{ |
| 114 | MaxTotalBytes: math.MaxUint64, |
| 115 | MaxTransactionCount: 0, |
| 116 | IndividualMaxTxSize: math.MaxUint32, |
| 117 | DropPercentage: 10, |
| 118 | }, |
| 119 | }, |
| 120 | toAdd: transaction, |
| 121 | }, |
| 122 | { |
| 123 | name: "recheck max tx count", |
| 124 | detail: "max tx count causes a recheck", |
| 125 | mempool: FeeMempool{ |
| 126 | pool: MempoolTxs{ |
| 127 | m: make(map[string]struct{}), |
| 128 | s: make([]MempoolTx, 0), |
| 129 | }, |
| 130 | txsBytes: 0, |
| 131 | config: MempoolConfig{ |
nothing calls this directly
no test coverage detected