From f0aa31b5bdef85914f05cd8304d5e945d1547b0d Mon Sep 17 00:00:00 2001 From: Fred Date: Wed, 11 Oct 2023 21:53:46 +0800 Subject: [PATCH] add order sign and verify test --- binding_tests/crypto_test.go | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/binding_tests/crypto_test.go b/binding_tests/crypto_test.go index 56f32d07..467cd955 100644 --- a/binding_tests/crypto_test.go +++ b/binding_tests/crypto_test.go @@ -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" ) @@ -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) +}