(t *testing.T)
| 23 | } |
| 24 | |
| 25 | func TestTxValidation(t *testing.T) { |
| 26 | var ( |
| 27 | tx *bc.Tx |
| 28 | vs *validationState |
| 29 | fixture *txFixture |
| 30 | |
| 31 | // the mux from tx, pulled out for convenience |
| 32 | mux *bc.Mux |
| 33 | ) |
| 34 | |
| 35 | cases := []struct { |
| 36 | desc string // description of the test case |
| 37 | f func() // function to adjust tx, vs, and/or mux |
| 38 | err error // expected error |
| 39 | }{ |
| 40 | { |
| 41 | desc: "base case", |
| 42 | }, |
| 43 | { |
| 44 | desc: "failing mux program", |
| 45 | f: func() { |
| 46 | mux.Program.Code = []byte{byte(vm.OP_FALSE)} |
| 47 | }, |
| 48 | err: vm.ErrFalseVMResult, |
| 49 | }, |
| 50 | { |
| 51 | desc: "unbalanced mux amounts", |
| 52 | f: func() { |
| 53 | mux.Sources[0].Value.Amount++ |
| 54 | iss := tx.Entries[*mux.Sources[0].Ref].(*bc.Issuance) |
| 55 | iss.WitnessDestination.Value.Amount++ |
| 56 | }, |
| 57 | err: errUnbalanced, |
| 58 | }, |
| 59 | { |
| 60 | desc: "overflowing mux source amounts", |
| 61 | f: func() { |
| 62 | mux.Sources[0].Value.Amount = math.MaxInt64 |
| 63 | iss := tx.Entries[*mux.Sources[0].Ref].(*bc.Issuance) |
| 64 | iss.WitnessDestination.Value.Amount = math.MaxInt64 |
| 65 | }, |
| 66 | err: errOverflow, |
| 67 | }, |
| 68 | { |
| 69 | desc: "underflowing mux destination amounts", |
| 70 | f: func() { |
| 71 | mux.WitnessDestinations[0].Value.Amount = math.MaxInt64 |
| 72 | out := tx.Entries[*mux.WitnessDestinations[0].Ref].(*bc.Output) |
| 73 | out.Source.Value.Amount = math.MaxInt64 |
| 74 | mux.WitnessDestinations[1].Value.Amount = math.MaxInt64 |
| 75 | out = tx.Entries[*mux.WitnessDestinations[1].Ref].(*bc.Output) |
| 76 | out.Source.Value.Amount = math.MaxInt64 |
| 77 | }, |
| 78 | err: errOverflow, |
| 79 | }, |
| 80 | { |
| 81 | desc: "unbalanced mux assets", |
| 82 | f: func() { |
nothing calls this directly
no test coverage detected