|
4 | 4 | "encoding/hex" |
5 | 5 | "testing" |
6 | 6 |
|
| 7 | + "github.com/bitcoin-sv/go-sdk/chainhash" |
7 | 8 | ec "github.com/bitcoin-sv/go-sdk/primitives/ec" |
8 | 9 | "github.com/bitcoin-sv/go-sdk/script" |
9 | 10 | "github.com/bitcoin-sv/go-sdk/transaction" |
@@ -153,3 +154,37 @@ func TestSignUnsigned(t *testing.T) { |
153 | 154 | require.NotEqual(t, tx.Inputs[i].UnlockingScript, cloneTx.Inputs[i].UnlockingScript) |
154 | 155 | } |
155 | 156 | } |
| 157 | + |
| 158 | +func TestSignUnsignedNew(t *testing.T) { |
| 159 | + pk, _ := ec.PrivateKeyFromWif("L1y6DgX4TuonxXzRPuk9reK2TD2THjwQReNUwVrvWN3aRkjcbauB") |
| 160 | + address, _ := script.NewAddressFromPublicKey(pk.PubKey(), true) |
| 161 | + tx := transaction.NewTransaction() |
| 162 | + lockingScript, err := p2pkh.Lock(address) |
| 163 | + require.NoError(t, err) |
| 164 | + sourceTxID, _ := chainhash.NewHashFromHex("fe77aa03d5563d3ec98455a76655ea3b58e19a4eb102baf7b2a47af37e94b295") |
| 165 | + unlockingScript, _ := p2pkh.Unlock(pk, nil) |
| 166 | + tx.AddInput(&transaction.TransactionInput{ |
| 167 | + SourceTransaction: &transaction.Transaction{ |
| 168 | + Outputs: []*transaction.TransactionOutput{ |
| 169 | + { |
| 170 | + Satoshis: 1, |
| 171 | + LockingScript: lockingScript, |
| 172 | + }, |
| 173 | + }, |
| 174 | + }, |
| 175 | + SourceTXID: sourceTxID, |
| 176 | + UnlockingScriptTemplate: unlockingScript, |
| 177 | + }) |
| 178 | + |
| 179 | + tx.AddOutput(&transaction.TransactionOutput{ |
| 180 | + Satoshis: 1, |
| 181 | + LockingScript: lockingScript, |
| 182 | + }) |
| 183 | + |
| 184 | + err = tx.SignUnsigned() |
| 185 | + require.NoError(t, err) |
| 186 | + |
| 187 | + for _, input := range tx.Inputs { |
| 188 | + require.Positive(t, len(input.UnlockingScript.Bytes())) |
| 189 | + } |
| 190 | +} |
0 commit comments