(t *testing.T, testCase taprootJsonTest)
| 1132 | } |
| 1133 | |
| 1134 | func executeTaprootRefTest(t *testing.T, testCase taprootJsonTest) { |
| 1135 | t.Helper() |
| 1136 | |
| 1137 | txHex, err := hex.DecodeString(testCase.Tx) |
| 1138 | if err != nil { |
| 1139 | t.Fatalf("unable to decode hex: %v", err) |
| 1140 | } |
| 1141 | tx, err := newTxFromBytes(txHex) |
| 1142 | if err != nil { |
| 1143 | t.Fatalf("unable to decode hex: %v", err) |
| 1144 | } |
| 1145 | |
| 1146 | var prevOut wire.TxOut |
| 1147 | |
| 1148 | prevOutFetcher := NewMultiPrevOutFetcher(nil) |
| 1149 | for i, prevOutString := range testCase.Prevouts { |
| 1150 | prevOutBytes, err := hex.DecodeString(prevOutString) |
| 1151 | if err != nil { |
| 1152 | t.Fatalf("unable to decode hex: %v", err) |
| 1153 | } |
| 1154 | |
| 1155 | var txOut wire.TxOut |
| 1156 | err = wire.ReadTxOut( |
| 1157 | bytes.NewReader(prevOutBytes), 0, 0, &txOut, |
| 1158 | ) |
| 1159 | if err != nil { |
| 1160 | t.Fatalf("unable to read utxo: %v", err) |
| 1161 | } |
| 1162 | |
| 1163 | prevOutFetcher.AddPrevOut( |
| 1164 | tx.TxIn[i].PreviousOutPoint, &txOut, |
| 1165 | ) |
| 1166 | |
| 1167 | if i == testCase.Index { |
| 1168 | prevOut = txOut |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | flags, err := parseScriptFlags(testCase.Flags) |
| 1173 | if err != nil { |
| 1174 | t.Fatalf("unable to parse flags: %v", err) |
| 1175 | } |
| 1176 | |
| 1177 | makeVM := func() *Engine { |
| 1178 | hashCache := NewTxSigHashes(tx, prevOutFetcher) |
| 1179 | |
| 1180 | vm, err := NewEngine( |
| 1181 | prevOut.PkScript, tx, testCase.Index, |
| 1182 | flags, nil, hashCache, prevOut.Value, prevOutFetcher, |
| 1183 | ) |
| 1184 | if err != nil { |
| 1185 | t.Fatalf("unable to create vm: %v", err) |
| 1186 | } |
| 1187 | |
| 1188 | return vm |
| 1189 | } |
| 1190 | |
| 1191 | if testCase.Success != nil { |
no test coverage detected
searching dependent graphs…