|
| 1 | +package ledger |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestBabbageBlockTransactions(t *testing.T) { |
| 8 | + b := &BabbageBlock{} |
| 9 | + |
| 10 | + t.Run("empty", func(t *testing.T) { |
| 11 | + if lenTxs := len(b.Transactions()); lenTxs != 0 { |
| 12 | + t.Fatalf("expected number of transactions is 0 but it was %d", lenTxs) |
| 13 | + } |
| 14 | + }) |
| 15 | + |
| 16 | + txsCount := 7 |
| 17 | + b.TransactionBodies = make([]BabbageTransactionBody, txsCount) |
| 18 | + b.TransactionWitnessSets = make([]BabbageTransactionWitnessSet, txsCount) |
| 19 | + |
| 20 | + for i := 0; i < txsCount; i++ { |
| 21 | + b.TransactionBodies[i] = BabbageTransactionBody{ |
| 22 | + TotalCollateral: 1 << i, |
| 23 | + } |
| 24 | + b.TransactionWitnessSets[i] = BabbageTransactionWitnessSet{ |
| 25 | + AlonzoTransactionWitnessSet: AlonzoTransactionWitnessSet{ |
| 26 | + ShelleyTransactionWitnessSet: ShelleyTransactionWitnessSet{ |
| 27 | + VkeyWitnesses: []interface{}{ |
| 28 | + append(make([]byte, 95), 1<<i), |
| 29 | + }, |
| 30 | + }, |
| 31 | + }, |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + t.Run("no invalid", func(t *testing.T) { |
| 36 | + txs := b.Transactions() |
| 37 | + |
| 38 | + if lenTxs := len(txs); lenTxs != txsCount { |
| 39 | + t.Fatalf("expected number of transactions is %d but it was %d", txsCount, lenTxs) |
| 40 | + } |
| 41 | + |
| 42 | + for i, tx := range txs { |
| 43 | + if btx := tx.(*BabbageTransaction); !btx.IsValid { |
| 44 | + t.Fatalf("expected transaction number %d IsValid is %v but is was %v", i, true, btx.IsValid) |
| 45 | + } |
| 46 | + } |
| 47 | + }) |
| 48 | + |
| 49 | + t.Run("with invalid", func(t *testing.T) { |
| 50 | + b.InvalidTransactions = []uint{2, 4, 5} |
| 51 | + txs := b.Transactions() |
| 52 | + |
| 53 | + if lenTxs := len(txs); lenTxs != txsCount { |
| 54 | + t.Fatalf("expected number of transactions is %d but it was %d", txsCount, lenTxs) |
| 55 | + } |
| 56 | + |
| 57 | + for i, tx := range txs { |
| 58 | + expected := i != 2 && i != 4 && i != 5 |
| 59 | + if btx := tx.(*BabbageTransaction); btx.IsValid != expected { |
| 60 | + t.Fatalf("expected transaction number %d IsValid is %v but is was %v", i, expected, btx.IsValid) |
| 61 | + } |
| 62 | + } |
| 63 | + }) |
| 64 | +} |
0 commit comments