-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsigma_test.go
75 lines (61 loc) · 1.9 KB
/
sigma_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package sigma
import (
"encoding/hex"
"testing"
"github.com/bitcoinschema/go-bitcoin/v2"
"github.com/libsv/go-bt/v2"
"github.com/libsv/go-bt/v2/bscript"
"github.com/stretchr/testify/assert"
)
func setupTx() *bt.Tx {
// Adjust this setup to match your TypeScript test setup
outputScriptAsm := "OP_0 OP_RETURN " + hex.EncodeToString([]byte("pushdata1")) + " " + hex.EncodeToString([]byte("pushdata2"))
script, _ := bscript.NewFromASM(outputScriptAsm)
tx := bt.NewTx()
tx.AddOutput(&bt.Output{
Satoshis: 0,
LockingScript: script,
})
// we must add an input
tx.Inputs = append(tx.Inputs, (&bt.Input{
PreviousTxSatoshis: 0,
PreviousTxScript: script,
PreviousTxOutIndex: 0,
SequenceNumber: 0,
UnlockingScript: &bscript.Script{},
}))
return tx
}
func TestSigma(t *testing.T) {
// ... Your setup code ...
tx := setupTx()
t.Run("signs and verifies a message correctly", func(t *testing.T) {
sigma := NewSigma(*tx, 0, 0, -1)
pk, err := bitcoin.CreatePrivateKey()
assert.Nil(t, err)
signResp := sigma.Sign(pk)
assert.NotNil(t, signResp.SigmaScript)
assert.Equal(t, "your-test-signature", signResp.Signature)
isValid := sigma.Verify()
assert.True(t, isValid)
})
// ... Your other test cases ...
}
// func TestGenerateOutputScript(t *testing.T) {
// // ... Your setup code ...
// tx := setupTx()
// t.Run("generates a correct output script", func(t *testing.T) {
// sigma := NewSigma(*tx, 0, 0, -1)
// out := sigma.getTargetTxOut()
// assert.NotNil(t, out)
// asm := out.LockingScript.String()
// signResp := sigma.Sign("your-test-signature", "your-test-address")
// assert.NotNil(t, signResp.SignedTx)
// signedTxOut := signResp.SignedTx.Outputs[0]
// assert.NotNil(t, signedTxOut)
// asmAfter := signedTxOut.LockingScript.String()
// assert.NotEqual(t, asm, asmAfter)
// })
// // ... Your other test cases ...
// }
// // ... Your other test functions ...