2018-08-09 01:06:34 +00:00
|
|
|
package types
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
ethcrypto "github.com/ethereum/go-ethereum/crypto"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestValidateSigner(t *testing.T) {
|
2018-08-30 21:36:14 +00:00
|
|
|
msgs := []sdk.Msg{sdk.NewTestMsg(sdk.AccAddress(TestAddr1.Bytes()))}
|
2018-08-09 01:06:34 +00:00
|
|
|
|
2018-08-24 15:29:10 +00:00
|
|
|
// create message signing structure and bytes
|
2018-08-30 21:36:14 +00:00
|
|
|
signBytes := GetStdTxSignBytes(TestChainID.String(), 0, 0, NewTestStdFee(), msgs, "")
|
2018-08-09 01:06:34 +00:00
|
|
|
|
|
|
|
// require signing not to fail
|
2018-08-30 21:36:14 +00:00
|
|
|
sig, err := ethcrypto.Sign(signBytes, TestPrivKey1)
|
2018-08-09 01:06:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// require signature to be valid
|
2018-08-30 21:36:14 +00:00
|
|
|
err = ValidateSigner(signBytes, sig, TestAddr1)
|
2018-08-09 01:06:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
2018-08-30 21:36:14 +00:00
|
|
|
sig, err = ethcrypto.Sign(signBytes, TestPrivKey2)
|
2018-08-09 01:06:34 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
// require signature to be invalid
|
2018-08-30 21:36:14 +00:00
|
|
|
err = ValidateSigner(signBytes, sig, TestAddr1)
|
|
|
|
require.Error(t, err)
|
|
|
|
|
|
|
|
// require invalid signature bytes return an error
|
|
|
|
err = ValidateSigner([]byte{}, sig, TestAddr2)
|
2018-08-09 01:06:34 +00:00
|
|
|
require.Error(t, err)
|
|
|
|
}
|