plugeth-statediff/test_helpers/chaingen/contract.go
Roy Crihfield d94b880cb7
All checks were successful
Test / Run compliance tests (pull_request) Successful in 4m36s
Test / Run unit tests (pull_request) Successful in 12m40s
Test / Run integration tests (pull_request) Successful in 29m9s
add chaingen & indexing test utils
2024-04-15 21:21:02 +08:00

31 lines
604 B
Go

package chaingen
import (
"strings"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
)
type ContractSpec struct {
DeploymentCode []byte
ABI abi.ABI
}
func ParseContract(abiStr, binStr string) (*ContractSpec, error) {
parsedABI, err := abi.JSON(strings.NewReader(abiStr))
if err != nil {
return nil, err
}
data := common.Hex2Bytes(binStr)
return &ContractSpec{data, parsedABI}, nil
}
func MustParseContract(abiStr, binStr string) *ContractSpec {
spec, err := ParseContract(abiStr, binStr)
if err != nil {
panic(err)
}
return spec
}