retest

package
v0.1.65 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2024 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RetestCmd = &cobra.Command{
	Use:   "retest [flags]",
	Short: "Convert the standard ETH test fillers into something to be replayed against an RPC",
	Long:  usage,
	RunE: func(cmd *cobra.Command, args []string) error {
		log.Info().Msg("starting")
		rawData, err := getInputData(cmd, args)
		if err != nil {
			return err
		}
		tests := make(EthTestSuite, 0)
		err = json.Unmarshal(rawData, &tests)
		if err != nil {
			return err
		}

		simpleTests := make([]any, 0)
		for testName, t := range tests {

			contractMap := make(map[string]string)
			if t.Solidity != "" {
				contractMap = solidityStringToBin(t.Solidity)
			}

			st := make(map[string]any)
			st["name"] = testName
			preDeploys := make([]map[string]string, 0)
			for addr, p := range t.Pre {
				if input, matched := checkContractMap(p.Code, contractMap); matched {
					p.Code = ":raw 0x" + input
				}

				dep := make(map[string]string)
				dep["label"] = fmt.Sprintf("pre:%s", addr)
				dep["addr"] = addr
				dep["code"] = WrapPredeployedCode(p)
				preDeploys = append(preDeploys, dep)
			}
			st["dependencies"] = preDeploys

			gasLimit := WrappedNumeric{raw: t.Transaction.GasLimit}
			gasLimits := gasLimit.ToSlice()
			txValue := WrappedNumeric{raw: t.Transaction.Value}
			txValues := txValue.ToSlice()
			wd := WrappedData{raw: t.Transaction.Data}
			wds := wd.ToSlice()

			testCases := make([]map[string]any, 0)

			for _, singleGas := range gasLimits {
				for _, singleValue := range txValues {
					for _, singleTx := range wds {
						tc := make(map[string]any)
						tc["name"] = testName

						if input, matched := checkContractMap(singleTx.raw, contractMap); matched {

							tc["input"] = input
						} else {
							tc["input"] = singleTx.ToString()
						}

						wTo := WrappedAddress{raw: t.Transaction.To}
						tc["to"] = wTo.ToString()
						tc["originalTo"] = t.Transaction.To

						tc["gas"] = singleGas.ToString()
						tc["originalGas"] = t.Transaction.GasLimit

						tc["value"] = singleValue.ToString()
						tc["originalValue"] = t.Transaction.Value

						testCases = append(testCases, tc)
					}
				}
			}

			for _, singleBlock := range t.Blocks {
				for _, singleTx := range singleBlock.Transactions {

					tc := make(map[string]any)
					tc["name"] = testName
					if input, matched := checkContractMap(singleTx.ChainID, contractMap); matched {

						tc["input"] = input
					} else {
						wrappedTxData := WrappedData{raw: singleTx.Data}
						tc["input"] = wrappedTxData.ToString()
					}

					wTo := WrappedAddress{raw: singleTx.To}
					tc["to"] = wTo.ToString()
					tc["originalTo"] = singleTx.To

					wrappedGas := WrappedNumeric{raw: singleTx.GasLimit}
					tc["gas"] = wrappedGas.ToString()
					tc["originalGas"] = singleTx.GasLimit

					wrappedVal := WrappedNumeric{raw: singleTx.Value}
					tc["value"] = wrappedVal.ToString()
					tc["originalValue"] = singleTx.Value

					testCases = append(testCases, tc)
				}

			}

			st["testCases"] = testCases

			simpleTests = append(simpleTests, st)
		}
		testOut, err := json.Marshal(simpleTests)
		if err != nil {
			return err
		}
		fmt.Println(string(testOut))
		return nil
	},
	Args: func(cmd *cobra.Command, args []string) error {
		return nil
	},
}

Functions

func EthTestDataToString

func EthTestDataToString(data EthTestData) string

func EthTestNumericToBigInt

func EthTestNumericToBigInt(num EthTestNumeric) *big.Int

func WrapCode

func WrapCode(inputData EthTestData) string

func WrapPredeployedCode

func WrapPredeployedCode(pre EthTestPre) string

WrapPredeployeCode will wrap a predeployed contract so that it can be deployed for testing. For now we're just wrapping the code so that it should match what the precondition is. In the future, this should also have a constructor that would initialize the storage slots to match the predeployed state. This will never be 100% right, but useful for smoke testing

Types

type EthTest

type EthTest struct {
	Pre                map[string]EthTestPre `json:"pre"`                // Pre determines preallocated accounts in the test case
	Transaction        EthTestTx             `json:"transaction"`        // Transaction is usually a test transaction
	Env                EthTestEnv            `json:"env"`                // Env sets the environment for execution. This is not relvant usually for creating load
	GenesisBlockHeader EthTestGenesis        `json:"genesisBlockHeader"` // GenesisBlockHeader sets the typical genesis params of the network.
	Blocks             []EthTestBlocks       `json:"blocks"`             // Blocks are the blocks that lead to the state being tested
	SealEngine         string                `json:"sealEngine"`         // SealEngine is either Null or NoProof
	Expect             any                   `json:"expect"`             // Expect are the success conditions. In our cases we won't be able to validate them
	Info               any                   `json:"_info"`              // Info mostly comments
	ExpectException    any                   `json:"expectException"`    // ExpectException also determines if errors are expected for certain levels of HF
	Vectors            any                   `json:"vectors"`            // Vectors are specific cases which we probably won't use
	TxBytes            any                   `json:"txbytes"`            // TxBytes are RLP tests to send directly without manipulation
	Result             any                   `json:"result"`             // Result are specific expected results
	Network            any                   `json:"network"`            // Network in rare cases seems to specify ArrayGlacier, Istanbul, or GrayGlacier
	Exceptions         any                   `json:"exceptions"`         // Exceptions specifies resulting errors
	Solidity           string                `json:"solidity"`           // Solidity contains a standard solidity file with one or more contracts
}

EthTest is based on examination of the data. We've left out the fields at are used in less then 10 tests

type EthTestAccessList

type EthTestAccessList struct {
	Address     EthTestAddress   `json:"address"`
	StorageKeys []EthTestNumeric `json:"storageKeys"`
}

type EthTestAddress

type EthTestAddress any

type EthTestBlocks

type EthTestBlocks struct {
	Transactions []EthTestTx `json:"transactions"`
}

type EthTestData

type EthTestData any

type EthTestEnv

type EthTestEnv struct {
	CurrentBaseFee       EthTestNumeric `json:"currentBaseFee"`
	CurrentCoinbase      EthTestAddress `json:"currentCoinbase"`
	CurrentDifficulty    EthTestNumeric `json:"currentDifficulty"`
	CurrentExcessBlobGas EthTestNumeric `json:"currentExcessBlobGas"`
	CurrentGasLimit      EthTestNumeric `json:"currentGasLimit"`
	CurrentNumber        EthTestNumeric `json:"currentNumber"`
	CurrentRandom        EthTestNumeric `json:"currentRandom"`
	CurrentTimestamp     EthTestNumeric `json:"currentTimestamp"`
}

type EthTestGenesis

type EthTestGenesis struct {
	BaseFeePerGas         EthTestNumeric `json:"baseFeePerGas"`
	BeaconRoot            EthTestHash    `json:"beaconRoot"`
	BlobGasUsed           EthTestNumeric `json:"blobGasUsed"`
	Bloom                 EthTestData    `json:"bloom"`
	Coinbase              EthTestAddress `json:"coinbase"`
	Difficulty            EthTestNumeric `json:"difficulty"`
	ExcessBlobGas         EthTestNumeric `json:"excessBlobGas"`
	ExtraData             EthTestData    `json:"extraData"`
	GasLimit              EthTestNumeric `json:"gasLimit"`
	GasUsed               EthTestNumeric `json:"gasUsed"`
	Hash                  EthTestHash    `json:"hash"`
	MixHash               EthTestHash    `json:"mixHash"`
	Nonce                 EthTestNumeric `json:"nonce"`
	Number                EthTestNumeric `json:"number"`
	ParentBeaconBlockRoot EthTestHash    `json:"parentBeaconBlockRoot"`
	ParentHash            EthTestHash    `json:"parentHash"`
	ReceiptTrie           EthTestHash    `json:"receiptTrie"`
	StateRoot             EthTestHash    `json:"stateRoot"`
	Timestamp             EthTestNumeric `json:"timestamp"`
	TransactionsTrie      EthTestHash    `json:"transactionsTrie"`
	UncleHash             EthTestHash    `json:"uncleHash"`
	WithdrawalsRoot       EthTestHash    `json:"withdrawalsRoot"`
}

type EthTestHash

type EthTestHash any

type EthTestNumeric

type EthTestNumeric any

type EthTestPre

type EthTestPre struct {
	Nonce   EthTestNumeric            `json:"nonce"`
	Balance EthTestNumeric            `json:"balance"`
	Storage map[string]EthTestNumeric `json:"storage"`
	Code    EthTestData               `json:"code"`
}

type EthTestSuite

type EthTestSuite map[string]EthTest

type EthTestTx

type EthTestTx struct {
	AccessList           []EthTestAccessList `json:"accessList"`
	BlobVersionedHashes  []EthTestHash       `json:"blobVersionedHashes"`
	ChainID              EthTestNumeric      `json:"chainId"`
	Data                 EthTestData         `json:"data"`
	GasLimit             EthTestNumeric      `json:"gasLimit"`
	GasPrice             EthTestNumeric      `json:"gasPrice"`
	MaxFeePerBlobGas     EthTestNumeric      `json:"maxFeePerBlobGas"`
	MaxFeePerGas         EthTestNumeric      `json:"maxFeePerGas"`
	MaxPriorityFeePerGas EthTestNumeric      `json:"maxPriorityFeePerGas"`
	Nonce                EthTestNumeric      `json:"nonce"`
	R                    EthTestNumeric      `json:"r"`
	S                    EthTestNumeric      `json:"s"`
	To                   EthTestAddress      `json:"to"`
	V                    EthTestNumeric      `json:"v"`
	Value                EthTestNumeric      `json:"value"`
	// Unused
	ExpectException any `json:"expectException"`
	SecretKey       any `json:"secretKey"`
}

type WrappedAddress

type WrappedAddress struct {
	// contains filtered or unexported fields
}

func (*WrappedAddress) ToString

func (wr *WrappedAddress) ToString() *ethcommon.Address

type WrappedData

type WrappedData struct {
	// contains filtered or unexported fields
}

func (*WrappedData) IsSlice

func (wr *WrappedData) IsSlice() bool

func (*WrappedData) ToSlice

func (wr *WrappedData) ToSlice() []*WrappedData

func (*WrappedData) ToString

func (wd *WrappedData) ToString() string

type WrappedNumeric

type WrappedNumeric struct {
	// contains filtered or unexported fields
}

func (*WrappedNumeric) IsSlice

func (wn *WrappedNumeric) IsSlice() bool

func (*WrappedNumeric) ToBigInt

func (wr *WrappedNumeric) ToBigInt() *big.Int

func (*WrappedNumeric) ToSlice

func (wn *WrappedNumeric) ToSlice() []*WrappedNumeric

func (*WrappedNumeric) ToString

func (wr *WrappedNumeric) ToString() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL