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

Added TestCases #3262

Open
wants to merge 15 commits into
base: sprint-1.14
Choose a base branch
from
48 changes: 48 additions & 0 deletions code/go/0chain.net/smartcontract/zcnsc/stakepool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ package zcnsc_test

import (
"encoding/hex"
// "errors"
"testing"

// "0chain.net/chaincore/chain/state"
// "0chain.net/chaincore/transaction"
"0chain.net/core/encryption"
// "0chain.net/smartcontract/stakepool"
// "0chain.net/smartcontract/stakepool/spenum"
// "0chain.net/smartcontract/zcnsc"
. "0chain.net/smartcontract/zcnsc"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -52,3 +58,45 @@ func Test_WhenAuthorizerDoesNotExists_StakePool_IsNotUpdatedOrCreated(t *testing
require.EqualError(t, err, "authorizer(authorizerID: "+authorizerID+") not found")
require.Empty(t, resp)
}
func Test_WhenAuthorizerDoesNotExists_StakePool_IsNotUpdatedOrCreated_With_Empty_AuthorizerID(t *testing.T) {
const authorizerID = ""
// Default authorizer transaction
ctx := MakeMockStateContext()
contract := CreateZCNSmartContract()
// Add UpdateAuthorizerStakePool
payload := CreateAuthorizerStakingPoolParamPayload(authorizerID)
tr, err := CreateTransaction(authorizerID, UpdateAuthorizerStakePoolFunc, payload, ctx)
require.NoError(t, err)
resp, err := contract.UpdateAuthorizerStakePool(tr, payload, ctx)
require.Error(t, err)
require.Empty(t, resp)
}
func Test_WhenAuthorizerDoesNotExists_StakePool_IsNotUpdatedOrCreated_With_Empty_PayLoad(t *testing.T) {
const authorizerID = "auth0"
// Default authorizer transaction
ctx := MakeMockStateContext()
contract := CreateZCNSmartContract()
// Add UpdateAuthorizerStakePool
var payload []byte
tr, err := CreateTransaction(authorizerID, UpdateAuthorizerStakePoolFunc, payload, ctx)
require.NoError(t, err)
resp, err := contract.UpdateAuthorizerStakePool(tr, payload, ctx)
require.Error(t, err)
require.Empty(t, resp)
}
func Test_WhenAuthorizerDoesNotExists_StakePool_poolSetting_With_Empty(t *testing.T) {
const authorizerID = "auth0"
// Default authorizer transaction
ctx := MakeMockStateContext()
contract := CreateZCNSmartContract()
params := UpdateAuthorizerStakePoolPayload{}
poolSettings := params.StakePoolSettings
poolSettings.DelegateWallet = ""
// Add UpdateAuthorizerStakePool
var payload []byte
tr, err := CreateTransaction(poolSettings.DelegateWallet, UpdateAuthorizerStakePoolFunc, payload, ctx)
require.NoError(t, err)
resp, err := contract.UpdateAuthorizerStakePool(tr, payload, ctx)
require.Error(t, err)
require.Empty(t, resp)
}