github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/execution/contexts/bond_context_test.go (about)

     1  package contexts
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/hyperledger/burrow/acm"
     7  	"github.com/hyperledger/burrow/acm/acmstate"
     8  	"github.com/hyperledger/burrow/acm/validator"
     9  	"github.com/hyperledger/burrow/crypto"
    10  	"github.com/hyperledger/burrow/execution/exec"
    11  	"github.com/hyperledger/burrow/logging"
    12  	"github.com/hyperledger/burrow/txs/payload"
    13  	"github.com/stretchr/testify/require"
    14  )
    15  
    16  func TestBondContext(t *testing.T) {
    17  	t.Run("CurveType", func(t *testing.T) {
    18  		privKey, err := crypto.GeneratePrivateKey(nil, crypto.CurveTypeSecp256k1)
    19  		require.NoError(t, err)
    20  		pubKey := privKey.GetPublicKey()
    21  		address := pubKey.GetAddress()
    22  
    23  		accountState := acmstate.NewMemoryState()
    24  		accountState.Accounts[address] = &acm.Account{
    25  			Address:   address,
    26  			PublicKey: pubKey,
    27  			Balance:   1337,
    28  		}
    29  
    30  		bondContext := &BondContext{
    31  			State:        accountState,
    32  			ValidatorSet: validator.NewSet(),
    33  			Logger:       logging.NewNoopLogger(),
    34  		}
    35  
    36  		err = bondContext.Execute(&exec.TxExecution{}, &payload.BondTx{
    37  			Input: &payload.TxInput{
    38  				Address: address,
    39  				Amount:  1337,
    40  			},
    41  		})
    42  		require.Error(t, err)
    43  	})
    44  }