Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Split key system test #1022

Open
wants to merge 6 commits into
base: sprint-1.13
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions tests/api_tests/set_wallet_info_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package api_tests

import (

Check failure on line 3 in tests/api_tests/set_wallet_info_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `goimports`-ed with -local github.com/golangci/golangci-lint (goimports)
"fmt"

Check failure on line 4 in tests/api_tests/set_wallet_info_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
"testing"
"encoding/base64"
"github.com/0chain/gosdk/zcncore"
"github.com/0chain/system_test/internal/api/util/test"
"github.com/stretchr/testify/require"
)

func TestSetWalletInfo(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)
t.SetSmokeTests("Check if setWalletInfo is setting splitkey wallet or not")

t.Run("Check if setWalletInfo is setting splitkey wallet or not", func(t *test.SystemTest) {
wallet := createWallet(t)
privateKey := wallet.Keys.PrivateKey
serializedPrivateKey := privateKey.Serialize()
stringPrivateKey := base64.StdEncoding.EncodeToString(serializedPrivateKey)
// this represents number of split keys made from private key
numSplit := 2
splitKeyWallet, err := zcncore.SplitKeys(stringPrivateKey, numSplit)
if err != nil {
fmt.Println("Error while spliting keys:", err)
return
}
// setwallet info takes a json string wallet (marshalled wallet)

Check failure on line 28 in tests/api_tests/set_wallet_info_test.go

View workflow job for this annotation

GitHub Actions / lint

`marshalled` is a misspelling of `marshaled` (misspell)
err = zcncore.SetWalletInfo(splitKeyWallet, true)
require.Nil(t, err)
require.NotNil(t, splitKeyWallet)
})
}
36 changes: 36 additions & 0 deletions tests/api_tests/split_key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package api_tests

import (
"encoding/json"

Check failure on line 4 in tests/api_tests/split_key_test.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
"encoding/base64"
"testing"

"github.com/0chain/gosdk/zcncore"
"github.com/0chain/system_test/internal/api/util/test"
"github.com/stretchr/testify/require"
"github.com/0chain/gosdk/core/zcncrypto"
)


func TestSplitKey(testSetup *testing.T) {
t := test.NewSystemTest(testSetup)
t.SetSmokeTests("Check if Splitkey handler is generating split keys or not")

t.Run("Check if Splitkey handler is generating split keys or not", func(t *test.SystemTest) {
wallet := createWallet(t)
privateKey := wallet.Keys.PrivateKey
serializedPrivateKey := privateKey.Serialize()
stringPrivateKey := base64.StdEncoding.EncodeToString(serializedPrivateKey)
// this represents number of split keys made from private key
numSplit := 2
wStr, err := zcncore.SplitKeys(stringPrivateKey, numSplit)
require.NoError(t, err, "failed to create split key wallet using private key")
var splitKeyWallet zcncrypto.Wallet
err = json.Unmarshal([]byte(wStr), &splitKeyWallet)
require.NoError(t, err, "failed to deserialize wallet object", wStr)
require.NotNil(t, splitKeyWallet)
require.Equal(t, splitKeyWallet.ClientID, wallet.Id)
require.NotNil(t, splitKeyWallet.Keys[0].PrivateKey)
require.NotNil(t, splitKeyWallet.Keys[0].PublicKey)
})
}
Loading