// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

// #skiplint: import_testing_only_in_tests
package precompilebind

// tmplSourcePrecompileConfigGo is the Go precompiled config source template.
const tmplSourcePrecompileConfigTestGo = `
// Code generated
// This file is a generated precompile config test with the skeleton of test functions.
// The file is generated by a template. Please inspect every code and comment in this file before use.

package {{.Package}}

import (
	"testing"

	"github.com/ava-labs/subnet-evm/precompile/precompileconfig"
	"github.com/ava-labs/subnet-evm/precompile/precompiletest"
	"github.com/ava-labs/subnet-evm/utils"
	{{- if .Contract.AllowList}}
	"github.com/ava-labs/subnet-evm/precompile/allowlist/allowlisttest"

	"github.com/ava-labs/libevm/common"
	{{- end}}
	"go.uber.org/mock/gomock"
)

// TestVerify tests the verification of Config.
func TestVerify(t *testing.T) {
	{{- if .Contract.AllowList}}
	admins := []common.Address{allowlisttest.TestAdminAddr}
	enableds := []common.Address{allowlisttest.TestEnabledAddr}
	managers := []common.Address{allowlisttest.TestManagerAddr}
	{{- end}}
	tests := map[string]precompiletest.ConfigVerifyTest{
		"valid config": {
			Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}),
			ChainConfig: func() precompileconfig.ChainConfig {
				config := precompileconfig.NewMockChainConfig(gomock.NewController(t))
				config.EXPECT().IsDurango(gomock.Any()).Return(true).AnyTimes()
				return config
			}(),
			ExpectedError: "",
		},
		// CUSTOM CODE STARTS HERE
		// Add your own Verify tests here, e.g.:
		// "your custom test name": {
		// 	Config: NewConfig(utils.NewUint64(3), {{- if .Contract.AllowList}} admins, enableds, managers{{- end}}),
		// 	ExpectedError: ErrYourCustomError.Error(),
		// },
	}
	{{- if .Contract.AllowList}}
	// Verify the precompile with the allowlist.
	// This adds allowlist verify tests to your custom tests
	// and runs them all together.
	// Even if you don't add any custom tests, keep this. This will still
	// run the default allowlist verify tests.
	allowlisttest.VerifyPrecompileWithAllowListTests(t, Module, tests)
	{{- else}}
			// Run verify tests.
		precompiletest.RunVerifyTests(t, tests)
	{{- end}}
}

// TestEqual tests the equality of Config with other precompile configs.
func TestEqual(t *testing.T) {
	{{- if .Contract.AllowList}}
	admins := []common.Address{allowlisttest.TestAdminAddr}
	enableds := []common.Address{allowlisttest.TestEnabledAddr}
	managers := []common.Address{allowlisttest.TestManagerAddr}
	{{- end}}
	tests := map[string]precompiletest.ConfigEqualTest{
		"non-nil config and nil other": {
			Config:   NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds,managers{{- end}}),
			Other:    nil,
			Expected: false,
		},
		"different type": {
			Config:   NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}),
			Other:    precompileconfig.NewMockConfig(gomock.NewController(t)),
			Expected: false,
		},
		"different timestamp": {
			Config:   NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}),
			Other:    NewConfig(utils.NewUint64(4){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}),
			Expected: false,
		},
		"same config": {
			Config: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}),
			Other: NewConfig(utils.NewUint64(3){{- if .Contract.AllowList}}, admins, enableds, managers{{- end}}),
			Expected: true,
		},
		// CUSTOM CODE STARTS HERE
		// Add your own Equal tests here
		}
		{{- if .Contract.AllowList}}
		// Run allow list equal tests.
		// This adds allowlist equal tests to your custom tests
		// and runs them all together.
		// Even if you don't add any custom tests, keep this. This will still
		// run the default allowlist equal tests.
		allowlisttest.EqualPrecompileWithAllowListTests(t, Module, tests)
		{{- else}}
		// Run equal tests.
		precompiletest.RunEqualTests(t, tests)
		{{- end}}
	}
`
