mirror of https://github.com/poanetwork/gecko.git
Merge pull request #64 from moreati/vms-avm-codecSetup
vms: Standardize on setupCodec() in avm tests
This commit is contained in:
commit
e750d442cf
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -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)
|
||||
|
|
|
@ -25,7 +25,7 @@ func TestTxNil(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTxEmpty(t *testing.T) {
|
||||
func setupCodec() codec.Codec {
|
||||
c := codec.NewDefault()
|
||||
c.RegisterType(&BaseTx{})
|
||||
c.RegisterType(&CreateAssetTx{})
|
||||
|
@ -37,7 +37,11 @@ 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")
|
||||
|
@ -45,17 +49,7 @@ func TestTxEmpty(t *testing.T) {
|
|||
}
|
||||
|
||||
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{
|
||||
|
@ -93,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{
|
||||
|
@ -161,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{
|
||||
|
|
|
@ -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"
|
||||
|
@ -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)
|
||||
|
@ -338,18 +326,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)
|
||||
|
|
Loading…
Reference in New Issue