services/scribe/testutil/contracttype.go
package testutil
import (
"github.com/ethereum/go-ethereum/common/compiler"
"github.com/synapsecns/sanguine/ethergo/contracts"
"github.com/synapsecns/sanguine/services/scribe/testutil/testcontract"
)
// set all contact types.
func init() {
for i := 0; i < len(_contractTypeImpl_index); i++ {
contractType := contractTypeImpl(i)
AllContractTypes = append(AllContractTypes, contractType)
// assert type is correct
var _ contracts.ContractType = contractType
}
}
// AllContractTypes is a list of all contract types. Since we use stringer and this is a testing library, instead
// of manually copying all these out we pull the names out of stringer. In order to make sure stringer is updated, we panic on
// any method called where the index is higher than the stringer array length.
var AllContractTypes []contractTypeImpl
// verifyStringerUpdated verifies stringer is up to date (this index is included in stringer).
func verifyStringerUpdated(contractType contractTypeImpl) {
if int(contractType) > len(_contractTypeImpl_index) {
panic("please update stringer before running test again")
}
}
// contractTypeImpl is the type of the contract being saved/fetched.
// we use an interface here so the deploy helper here can be abstracted away from the synapse contracts
//
//go:generate go run golang.org/x/tools/cmd/stringer -type=contractTypeImpl -linecomment
type contractTypeImpl int
const (
// TestContractType is the type of the test contract.
TestContractType contractTypeImpl = iota
)
// ID gets the contract type as an id.
func (c contractTypeImpl) ID() int {
verifyStringerUpdated(c)
return int(c)
}
// Name gets the name of the contract.
func (c contractTypeImpl) Name() string {
verifyStringerUpdated(c)
return c.String()
}
// ContractInfo gets the source code of every contract. See TODO above.
// TODO these should use contract name and maybe come out of the generator.
//
//nolint:cyclop
func (c contractTypeImpl) ContractInfo() *compiler.Contract {
switch c {
case TestContractType:
return testcontract.Contracts["solidity/TestContract.sol:TestContract"]
default:
panic("not yet implemented")
}
}
// ContractName gets the name of the deployed contract.
func (c contractTypeImpl) ContractName() string {
return c.Name()
}
// make sure contractTypeImpl conforms to contracts.ContractType.
var _ contracts.ContractType = contractTypeImpl(1)