2020-07-02 16:04:45 +08:00
|
|
|
package tester
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/meshplus/bitxhub-kit/crypto"
|
2020-08-11 14:07:15 +08:00
|
|
|
"github.com/meshplus/bitxhub-kit/crypto/asym"
|
2020-07-02 16:04:45 +08:00
|
|
|
"github.com/meshplus/bitxhub-model/pb"
|
|
|
|
"github.com/meshplus/bitxhub/internal/constant"
|
|
|
|
"github.com/meshplus/bitxhub/internal/coreapi/api"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Store struct {
|
|
|
|
suite.Suite
|
|
|
|
api api.CoreAPI
|
|
|
|
privKey crypto.PrivateKey
|
|
|
|
pubKey crypto.PublicKey
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *Store) SetupSuite() {
|
|
|
|
var err error
|
2020-08-11 14:07:15 +08:00
|
|
|
suite.privKey, err = asym.GenerateKeyPair(crypto.Secp256k1)
|
2020-07-02 16:04:45 +08:00
|
|
|
suite.Assert().Nil(err)
|
|
|
|
|
|
|
|
suite.pubKey = suite.privKey.PublicKey()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *Store) TestStore() {
|
2020-08-11 14:07:15 +08:00
|
|
|
k, err := asym.GenerateKeyPair(crypto.Secp256k1)
|
2020-07-02 16:04:45 +08:00
|
|
|
suite.Require().Nil(err)
|
2020-09-29 15:01:30 +08:00
|
|
|
kNonce := uint64(1)
|
2020-07-02 16:04:45 +08:00
|
|
|
|
|
|
|
args := []*pb.Arg{
|
|
|
|
pb.String("123"),
|
|
|
|
pb.String("abc"),
|
|
|
|
}
|
|
|
|
|
2020-09-29 15:01:30 +08:00
|
|
|
ret, err := invokeBVMContract(suite.api, k, kNonce, constant.StoreContractAddr.Address(), "Set", args...)
|
2020-07-02 16:04:45 +08:00
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(ret.IsSuccess())
|
2020-09-29 15:01:30 +08:00
|
|
|
kNonce++
|
2020-07-02 16:04:45 +08:00
|
|
|
|
2020-09-29 15:01:30 +08:00
|
|
|
ret2, err := invokeBVMContract(suite.api, k, kNonce, constant.StoreContractAddr.Address(), "Get", pb.String("123"))
|
2020-07-02 16:04:45 +08:00
|
|
|
suite.Require().Nil(err)
|
|
|
|
suite.Require().True(ret2.IsSuccess())
|
|
|
|
suite.Require().Equal("abc", string(ret2.Ret))
|
2020-09-29 15:01:30 +08:00
|
|
|
kNonce++
|
2020-07-02 16:04:45 +08:00
|
|
|
}
|