github.com/cgcardona/r-subnet-evm@v0.1.5/accounts/abi/bind/precompilebind/precompile_config_test_template.go (about)

     1  // (c) 2019-2022, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  package precompilebind
     4  
     5  // tmplSourcePrecompileConfigGo is the Go precompiled config source template.
     6  const tmplSourcePrecompileConfigTestGo = `
     7  // Code generated
     8  // This file is a generated precompile config test with the skeleton of test functions.
     9  // The file is generated by a template. Please inspect every code and comment in this file before use.
    10  
    11  package {{.Package}}
    12  
    13  import (
    14  	"math/big"
    15  	"testing"
    16  
    17  	"github.com/cgcardona/r-subnet-evm/precompile/precompileconfig"
    18  	"github.com/cgcardona/r-subnet-evm/precompile/testutils"
    19  	{{- if .Contract.AllowList}}
    20  	"github.com/cgcardona/r-subnet-evm/precompile/allowlist"
    21  
    22  	"github.com/ethereum/go-ethereum/common"
    23  	{{- end}}
    24  )
    25  
    26  // TestVerify tests the verification of Config.
    27  func TestVerify(t *testing.T) {
    28  	{{- if .Contract.AllowList}}
    29  	admins := []common.Address{allowlist.TestAdminAddr}
    30  	enableds := []common.Address{allowlist.TestEnabledAddr}
    31  	{{- end}}
    32  	tests := map[string]testutils.ConfigVerifyTest{
    33  		"valid config": {
    34  			Config: NewConfig(big.NewInt(3){{- if .Contract.AllowList}}, admins, enableds{{- end}}),
    35  			ExpectedError: "",
    36  		},
    37  		// CUSTOM CODE STARTS HERE
    38  		// Add your own Verify tests here, e.g.:
    39  		// "your custom test name": {
    40  		// 	Config: NewConfig(big.NewInt(3), {{- if .Contract.AllowList}} admins, enableds{{- end}}),
    41  		// 	ExpectedError: ErrYourCustomError.Error(),
    42  		// },
    43  	}
    44  	{{- if .Contract.AllowList}}
    45  	// Verify the precompile with the allowlist.
    46  	// This adds allowlist verify tests to your custom tests
    47  	// and runs them all together.
    48  	// Even if you don't add any custom tests, keep this. This will still
    49  	// run the default allowlist verify tests.
    50  	allowlist.VerifyPrecompileWithAllowListTests(t, Module, tests)
    51  	{{- else}}
    52  	// Run verify tests.
    53  	testutils.RunVerifyTests(t, tests)
    54  	{{- end}}
    55  }
    56  
    57  // TestEqual tests the equality of Config with other precompile configs.
    58  func TestEqual(t *testing.T) {
    59  	{{- if .Contract.AllowList}}
    60  	admins := []common.Address{allowlist.TestAdminAddr}
    61  	enableds := []common.Address{allowlist.TestEnabledAddr}
    62  	{{- end}}
    63  	tests := map[string]testutils.ConfigEqualTest{
    64  		"non-nil config and nil other": {
    65  			Config:   NewConfig(big.NewInt(3){{- if .Contract.AllowList}}, admins, enableds{{- end}}),
    66  			Other:    nil,
    67  			Expected: false,
    68  		},
    69  		"different type": {
    70  			Config:   NewConfig(big.NewInt(3){{- if .Contract.AllowList}}, admins, enableds{{- end}}),
    71  			Other:    precompileconfig.NewNoopStatefulPrecompileConfig(),
    72  			Expected: false,
    73  		},
    74  		"different timestamp": {
    75  			Config:   NewConfig(big.NewInt(3){{- if .Contract.AllowList}}, admins, enableds{{- end}}),
    76  			Other:    NewConfig(big.NewInt(4){{- if .Contract.AllowList}}, admins, enableds{{- end}}),
    77  			Expected: false,
    78  		},
    79  		"same config": {
    80  			Config: NewConfig(big.NewInt(3){{- if .Contract.AllowList}}, admins, enableds{{- end}}),
    81  			Other: NewConfig(big.NewInt(3){{- if .Contract.AllowList}}, admins, enableds{{- end}}),
    82  			Expected: true,
    83  		},
    84  		// CUSTOM CODE STARTS HERE
    85  		// Add your own Equal tests here
    86  		}
    87  		{{- if .Contract.AllowList}}
    88  		// Run allow list equal tests.
    89  		// This adds allowlist equal tests to your custom tests
    90  		// and runs them all together.
    91  		// Even if you don't add any custom tests, keep this. This will still
    92  		// run the default allowlist equal tests.
    93  		allowlist.EqualPrecompileWithAllowListTests(t, Module, tests)
    94  		{{- else}}
    95  		// Run equal tests.
    96  		testutils.RunEqualTests(t, tests)
    97  		{{- end}}
    98  	}
    99  `