Skip to content

Commit

Permalink
add order sign and verify test
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred0327 committed Oct 11, 2023
1 parent 32634d7 commit f0aa31b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions binding_tests/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package binding_tests
import (
sdk "github.com/zkLinkProtocol/zklink_sdk/binding_tests/generated/uniffi/zklink_sdk"
"github.com/stretchr/testify/assert"
"fmt"
"math/big"
"testing"
)

Expand Down Expand Up @@ -40,3 +42,41 @@ func TestZkLinkSigner(t *testing.T) {
is_ok := sdk.VerifyMusig(signature, msg)
assert.Equal(t, is_ok, true)
}

func TestVerifyOrderSignature(t *testing.T) {
privateKey := "0xbe725250b123a39dab5b7579334d5888987c72a58f4508062545fe6e08ca94f4"
zklinkSigner, err := sdk.ZkLinkSignerNewFromHexEthSigner(privateKey)
if err != nil {
return
}
order := sdk.NewOrder(
sdk.AccountId(1),
sdk.SubAccountId(1),
sdk.SlotId(3),
sdk.Nonce(1),
sdk.TokenId(18),
sdk.TokenId(145),
*big.NewInt(323289),
*big.NewInt(135),
true,
2,
5,
nil,
)
signedOrder, err := sdk.CreateSignedOrder(
zklinkSigner,
order,
)
orderMessage := order.GetBytes()
fmt.Printf("signed order signature:%v\n", signedOrder.Signature())
signature := sdk.ZkLinkSignature{
PubKey: "0xc4770f582ebc35c9c801bf262bde32737af2a739d322fccfb61fa4e2efb30cad",
Signature: "0x87f8ceee886a937cc26e31be674944fd18b8ba026eec04f4a3c82d0b8c92a2064ca5e115ac73e973fe5226936edea55cf2ad654401beea687af8ee21ba75fc00",
}

v := sdk.VerifyMusig(signature, orderMessage)
fmt.Println(v)
assert.Equal(t, v, false)
v = sdk.VerifyMusig(signedOrder.Signature(), orderMessage)
assert.Equal(t, v, true)
}

0 comments on commit f0aa31b

Please sign in to comment.