Skip to content

Commit

Permalink
Merge branch 'vms-avm-service-test' of github.com:moreati/gecko into …
Browse files Browse the repository at this point in the history
…vms-avm-service-test
  • Loading branch information
moreati committed Apr 16, 2020
2 parents 91f4c85 + 67c1783 commit cadbd23
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 205 deletions.
145 changes: 12 additions & 133 deletions vms/avm/base_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/ava-labs/gecko/snow/engine/common"
"github.com/ava-labs/gecko/utils/crypto"
"github.com/ava-labs/gecko/vms/components/ava"
"github.com/ava-labs/gecko/vms/components/codec"
"github.com/ava-labs/gecko/vms/secp256k1fx"
)

Expand Down Expand Up @@ -108,17 +107,7 @@ func TestBaseTxSerialization(t *testing.T) {
}},
}}

c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()

b, err := c.Marshal(&tx.UnsignedTx)
if err != nil {
Expand Down Expand Up @@ -185,17 +174,7 @@ func TestBaseTxGetters(t *testing.T) {
}

func TestBaseTxSyntacticVerify(t *testing.T) {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()

tx := &BaseTx{
NetID: networkID,
Expand Down Expand Up @@ -237,17 +216,7 @@ func TestBaseTxSyntacticVerify(t *testing.T) {
}

func TestBaseTxSyntacticVerifyNil(t *testing.T) {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()

tx := (*BaseTx)(nil)
if err := tx.SyntacticVerify(ctx, c, 0); err == nil {
Expand All @@ -256,17 +225,7 @@ func TestBaseTxSyntacticVerifyNil(t *testing.T) {
}

func TestBaseTxSyntacticVerifyWrongNetworkID(t *testing.T) {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()

tx := &BaseTx{
NetID: 0,
Expand Down Expand Up @@ -308,17 +267,7 @@ func TestBaseTxSyntacticVerifyWrongNetworkID(t *testing.T) {
}

func TestBaseTxSyntacticVerifyWrongChainID(t *testing.T) {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()

tx := &BaseTx{
NetID: networkID,
Expand Down Expand Up @@ -360,17 +309,7 @@ func TestBaseTxSyntacticVerifyWrongChainID(t *testing.T) {
}

func TestBaseTxSyntacticVerifyInvalidOutput(t *testing.T) {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()

tx := &BaseTx{
NetID: networkID,
Expand Down Expand Up @@ -403,17 +342,7 @@ func TestBaseTxSyntacticVerifyInvalidOutput(t *testing.T) {
}

func TestBaseTxSyntacticVerifyUnsortedOutputs(t *testing.T) {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()

tx := &BaseTx{
NetID: networkID,
Expand Down Expand Up @@ -469,17 +398,7 @@ func TestBaseTxSyntacticVerifyUnsortedOutputs(t *testing.T) {
}

func TestBaseTxSyntacticVerifyInvalidInput(t *testing.T) {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()

tx := &BaseTx{
NetID: networkID,
Expand All @@ -504,17 +423,7 @@ func TestBaseTxSyntacticVerifyInvalidInput(t *testing.T) {
}

func TestBaseTxSyntacticVerifyInputOverflow(t *testing.T) {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()

tx := &BaseTx{
NetID: networkID,
Expand Down Expand Up @@ -576,17 +485,7 @@ func TestBaseTxSyntacticVerifyInputOverflow(t *testing.T) {
}

func TestBaseTxSyntacticVerifyOutputOverflow(t *testing.T) {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()

tx := &BaseTx{
NetID: networkID,
Expand Down Expand Up @@ -640,17 +539,7 @@ func TestBaseTxSyntacticVerifyOutputOverflow(t *testing.T) {
}

func TestBaseTxSyntacticVerifyInsufficientFunds(t *testing.T) {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()

tx := &BaseTx{
NetID: networkID,
Expand Down Expand Up @@ -692,17 +581,7 @@ func TestBaseTxSyntacticVerifyInsufficientFunds(t *testing.T) {
}

func TestBaseTxSyntacticVerifyUninitialized(t *testing.T) {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()

tx := &BaseTx{
NetID: networkID,
Expand Down
14 changes: 1 addition & 13 deletions vms/avm/import_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/ava-labs/gecko/utils/crypto"
"github.com/ava-labs/gecko/utils/logging"
"github.com/ava-labs/gecko/vms/components/ava"
"github.com/ava-labs/gecko/vms/components/codec"
"github.com/ava-labs/gecko/vms/secp256k1fx"
)

Expand Down Expand Up @@ -89,18 +88,7 @@ func TestImportTxSerialization(t *testing.T) {
}},
}}

c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})

c := setupCodec()
b, err := c.Marshal(&tx.UnsignedTx)
if err != nil {
t.Fatal(err)
Expand Down
45 changes: 11 additions & 34 deletions vms/avm/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ func TestTxNil(t *testing.T) {
if err := tx.SyntacticVerify(ctx, c, 1); err == nil {
t.Fatalf("Should have errored due to nil tx")
}
if err := tx.SemanticVerify(nil, nil); err == nil {
t.Fatalf("Should have errored due to nil tx")
}
}

func TestTxEmpty(t *testing.T) {
func setupCodec() codec.Codec {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
Expand All @@ -34,25 +37,19 @@ func TestTxEmpty(t *testing.T) {
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
return c
}

func TestTxEmpty(t *testing.T) {
c := setupCodec()
tx := &Tx{}
if err := tx.SyntacticVerify(ctx, c, 1); err == nil {
t.Fatalf("Should have errored due to nil tx")
}
}

func TestTxInvalidCredential(t *testing.T) {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()
c.RegisterType(&ava.TestVerifiable{})

tx := &Tx{
Expand Down Expand Up @@ -90,17 +87,7 @@ func TestTxInvalidCredential(t *testing.T) {
}

func TestTxInvalidUnsignedTx(t *testing.T) {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()
c.RegisterType(&ava.TestVerifiable{})

tx := &Tx{
Expand Down Expand Up @@ -158,17 +145,7 @@ func TestTxInvalidUnsignedTx(t *testing.T) {
}

func TestTxInvalidNumberOfCredentials(t *testing.T) {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})
c := setupCodec()
c.RegisterType(&ava.TestVerifiable{})

tx := &Tx{
Expand Down
27 changes: 2 additions & 25 deletions vms/avm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/ava-labs/gecko/utils/hashing"
"github.com/ava-labs/gecko/utils/units"
"github.com/ava-labs/gecko/vms/components/ava"
"github.com/ava-labs/gecko/vms/components/codec"
"github.com/ava-labs/gecko/vms/components/verify"
"github.com/ava-labs/gecko/vms/nftfx"
"github.com/ava-labs/gecko/vms/propertyfx"
Expand Down Expand Up @@ -50,18 +49,7 @@ func init() {
}

func GetFirstTxFromGenesisTest(genesisBytes []byte, t *testing.T) *Tx {
c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})

c := setupCodec()
genesis := Genesis{}
if err := c.Unmarshal(genesisBytes, &genesis); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -390,18 +378,7 @@ func TestTxSerialization(t *testing.T) {
})
}

c := codec.NewDefault()
c.RegisterType(&BaseTx{})
c.RegisterType(&CreateAssetTx{})
c.RegisterType(&OperationTx{})
c.RegisterType(&ImportTx{})
c.RegisterType(&ExportTx{})
c.RegisterType(&secp256k1fx.TransferInput{})
c.RegisterType(&secp256k1fx.MintOutput{})
c.RegisterType(&secp256k1fx.TransferOutput{})
c.RegisterType(&secp256k1fx.MintOperation{})
c.RegisterType(&secp256k1fx.Credential{})

c := setupCodec()
b, err := c.Marshal(tx)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit cadbd23

Please sign in to comment.