Skip to content

Commit

Permalink
unify return data name
Browse files Browse the repository at this point in the history
  • Loading branch information
ramtinms committed Jun 6, 2024
1 parent 6cd6802 commit ddc729d
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 49 deletions.
4 changes: 2 additions & 2 deletions fvm/evm/emulator/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func (proc *procedure) deployAt(
tracer.CaptureStart(proc.evm, caller.ToCommon(), to.ToCommon(), true, data, gasLimit, value)

defer func() {
tracer.CaptureEnd(res.ReturnedValue, res.GasConsumed, res.VMError)
tracer.CaptureEnd(res.ReturnedData, res.GasConsumed, res.VMError)
}()
}

Expand Down Expand Up @@ -525,7 +525,7 @@ func (proc *procedure) run(
res.Index = uint16(txIndex)
// we need to capture the returned value no matter the status
// if the tx is reverted the error message is returned as returned value
res.ReturnedValue = execResult.ReturnData
res.ReturnedData = execResult.ReturnData

if !execResult.Failed() { // collect vm errors
// If the transaction created a contract, store the creation address in the receipt,
Expand Down
12 changes: 6 additions & 6 deletions fvm/evm/emulator/emulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestContractInteraction(t *testing.T) {
require.NoError(t, err)
nonce += 1

ret := new(big.Int).SetBytes(res.ReturnedValue)
ret := new(big.Int).SetBytes(res.ReturnedData)
require.Equal(t, num, ret)
require.GreaterOrEqual(t, res.GasConsumed, uint64(23_000))
})
Expand All @@ -233,7 +233,7 @@ func TestContractInteraction(t *testing.T) {
require.NoError(t, err)
nonce += 1

ret := new(big.Int).SetBytes(res.ReturnedValue)
ret := new(big.Int).SetBytes(res.ReturnedData)
require.Equal(t, blockNumber, ret)
})
})
Expand All @@ -253,7 +253,7 @@ func TestContractInteraction(t *testing.T) {
require.NoError(t, err)
nonce += 1
require.Error(t, res.VMError)
strings.Contains(string(res.ReturnedValue), "Assert Error Message")
strings.Contains(string(res.ReturnedData), "Assert Error Message")
})
})

Expand All @@ -272,7 +272,7 @@ func TestContractInteraction(t *testing.T) {
require.NoError(t, err)
nonce += 1
require.Error(t, res.VMError)
strings.Contains(string(res.ReturnedValue), "Value is too low")
strings.Contains(string(res.ReturnedData), "Value is too low")
})
})

Expand All @@ -293,7 +293,7 @@ func TestContractInteraction(t *testing.T) {
require.NoError(t, err)
nonce += 1

ret := new(big.Int).SetBytes(res.ReturnedValue)
ret := new(big.Int).SetBytes(res.ReturnedData)
require.Equal(t, types.FlowEVMPreviewNetChainID, ret)
})
})
Expand Down Expand Up @@ -791,7 +791,7 @@ func TestCallingExtraPrecompiles(t *testing.T) {
),
)
require.NoError(t, err)
require.Equal(t, output, res.ReturnedValue)
require.Equal(t, output, res.ReturnedData)
})
})
})
Expand Down
18 changes: 9 additions & 9 deletions fvm/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func TestEVMRun(t *testing.T) {
require.Equal(t, types.ErrCodeNoError, res.ErrorCode)
require.Empty(t, res.ErrorMessage)
require.Nil(t, res.DeployedContractAddress)
require.Equal(t, num, new(big.Int).SetBytes(res.ReturnedValue).Int64())
require.Equal(t, num, new(big.Int).SetBytes(res.ReturnedData).Int64())
})
})

Expand Down Expand Up @@ -317,7 +317,7 @@ func TestEVMRun(t *testing.T) {
require.Equal(t, types.StatusSuccessful, res.Status)
require.Equal(t, types.ErrCodeNoError, res.ErrorCode)
require.Empty(t, res.ErrorMessage)
require.Equal(t, int64(0), new(big.Int).SetBytes(res.ReturnedValue).Int64())
require.Equal(t, int64(0), new(big.Int).SetBytes(res.ReturnedData).Int64())
})
})

Expand Down Expand Up @@ -584,7 +584,7 @@ func TestEVMBatchRun(t *testing.T) {
require.Equal(t, types.StatusSuccessful, res.Status)
require.Equal(t, types.ErrCodeNoError, res.ErrorCode)
require.Empty(t, res.ErrorMessage)
require.Equal(t, storedValues[len(storedValues)-1], new(big.Int).SetBytes(res.ReturnedValue).Int64())
require.Equal(t, storedValues[len(storedValues)-1], new(big.Int).SetBytes(res.ReturnedData).Int64())
})
})

Expand Down Expand Up @@ -724,7 +724,7 @@ func TestEVMBatchRun(t *testing.T) {
require.Equal(t, types.StatusSuccessful, res.Status)
require.Equal(t, types.ErrCodeNoError, res.ErrorCode)
require.Empty(t, res.ErrorMessage)
require.Equal(t, num, new(big.Int).SetBytes(res.ReturnedValue).Int64())
require.Equal(t, num, new(big.Int).SetBytes(res.ReturnedData).Int64())
})
})

Expand Down Expand Up @@ -869,7 +869,7 @@ func TestEVMBatchRun(t *testing.T) {
require.Equal(t, types.ErrCodeNoError, res.ErrorCode)
require.Equal(t, types.StatusSuccessful, res.Status)
require.Empty(t, res.ErrorMessage)
require.Equal(t, num, new(big.Int).SetBytes(res.ReturnedValue).Int64())
require.Equal(t, num, new(big.Int).SetBytes(res.ReturnedData).Int64())
})
})
}
Expand Down Expand Up @@ -933,7 +933,7 @@ func TestEVMBlockData(t *testing.T) {
require.Equal(t, types.StatusSuccessful, res.Status)
require.Equal(t, types.ErrCodeNoError, res.ErrorCode)
require.Empty(t, res.ErrorMessage)
require.Equal(t, ctx.BlockHeader.Timestamp.Unix(), new(big.Int).SetBytes(res.ReturnedValue).Int64())
require.Equal(t, ctx.BlockHeader.Timestamp.Unix(), new(big.Int).SetBytes(res.ReturnedData).Int64())

})
}
Expand Down Expand Up @@ -1364,7 +1364,7 @@ func TestCadenceOwnedAccountFunctionalities(t *testing.T) {
require.Empty(t, res.ErrorMessage)
require.NotNil(t, res.DeployedContractAddress)
// we strip away first few bytes because they contain deploy code
require.Equal(t, testContract.ByteCode[17:], []byte(res.ReturnedValue))
require.Equal(t, testContract.ByteCode[17:], []byte(res.ReturnedData))
})
})
}
Expand Down Expand Up @@ -1535,7 +1535,7 @@ func TestDryRun(t *testing.T) {
require.Equal(t, types.StatusSuccessful, res.Status)
require.Equal(t, types.ErrCodeNoError, res.ErrorCode)
// make sure the value we used in the dry-run is not the same as the value stored in contract
require.NotEqual(t, updatedValue, new(big.Int).SetBytes(res.ReturnedValue).Int64())
require.NotEqual(t, updatedValue, new(big.Int).SetBytes(res.ReturnedData).Int64())
})
})

Expand All @@ -1560,7 +1560,7 @@ func TestDryRun(t *testing.T) {
require.Equal(t, types.ErrCodeNoError, result.ErrorCode)
require.Equal(t, types.StatusSuccessful, result.Status)
require.Greater(t, result.GasConsumed, uint64(0))
require.NotNil(t, result.ReturnedValue)
require.NotNil(t, result.ReturnedData)
require.NotNil(t, result.DeployedContractAddress)
require.NotEmpty(t, result.DeployedContractAddress.String())
})
Expand Down
38 changes: 19 additions & 19 deletions fvm/evm/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func TestHandler_TransactionRunOrPanic(t *testing.T) {
aa := handler.NewAddressAllocator()

result := &types.Result{
ReturnedValue: testutils.RandomData(t),
GasConsumed: testutils.RandomGas(1000),
ReturnedData: testutils.RandomData(t),
GasConsumed: testutils.RandomGas(1000),
Logs: []*gethTypes.Log{
testutils.GetRandomLogFixture(t),
testutils.GetRandomLogFixture(t),
Expand Down Expand Up @@ -443,7 +443,7 @@ func TestHandler_COA(t *testing.T) {
0, 0, 0, 0, 0, 0, 0, 0,
})
require.Equal(t, types.StatusSuccessful, ret.Status)
require.Equal(t, expected, ret.ReturnedValue)
require.Equal(t, expected, ret.ReturnedData)
})
})
})
Expand Down Expand Up @@ -593,7 +593,7 @@ func TestHandler_COA(t *testing.T) {
require.NotNil(t, result.DeployedContractAddress)
addr := *result.DeployedContractAddress
// skip first few bytes as they are deploy codes
assert.Equal(t, testContract.ByteCode[17:], []byte(result.ReturnedValue))
assert.Equal(t, testContract.ByteCode[17:], []byte(result.ReturnedData))
require.NotNil(t, addr)

num := big.NewInt(22)
Expand All @@ -609,7 +609,7 @@ func TestHandler_COA(t *testing.T) {
math.MaxUint64,
types.NewBalanceFromUFix64(0))

require.Equal(t, num, res.ReturnedValue.AsBigInt())
require.Equal(t, num, res.ReturnedData.AsBigInt())
})
})
})
Expand All @@ -634,7 +634,7 @@ func TestHandler_COA(t *testing.T) {
arch := handler.MakePrecompileAddress(1)

ret := foa.Call(arch, precompiles.FlowBlockHeightFuncSig[:], math.MaxUint64, types.NewBalanceFromUFix64(0))
require.Equal(t, big.NewInt(int64(blockHeight)), new(big.Int).SetBytes(ret.ReturnedValue))
require.Equal(t, big.NewInt(int64(blockHeight)), new(big.Int).SetBytes(ret.ReturnedData))
})
})
})
Expand Down Expand Up @@ -670,7 +670,7 @@ func TestHandler_COA(t *testing.T) {
math.MaxUint64,
types.EmptyBalance)

require.Equal(t, random.Bytes(), []byte(ret.ReturnedValue))
require.Equal(t, random.Bytes(), []byte(ret.ReturnedData))
})
})
})
Expand All @@ -692,8 +692,8 @@ func TestHandler_TransactionRun(t *testing.T) {
aa := handler.NewAddressAllocator()

result := &types.Result{
ReturnedValue: testutils.RandomData(t),
GasConsumed: testutils.RandomGas(1000),
ReturnedData: testutils.RandomData(t),
GasConsumed: testutils.RandomGas(1000),
Logs: []*gethTypes.Log{
testutils.GetRandomLogFixture(t),
testutils.GetRandomLogFixture(t),
Expand Down Expand Up @@ -736,9 +736,9 @@ func TestHandler_TransactionRun(t *testing.T) {
aa := handler.NewAddressAllocator()

result := &types.Result{
VMError: gethVM.ErrOutOfGas,
ReturnedValue: testutils.RandomData(t),
GasConsumed: testutils.RandomGas(1000),
VMError: gethVM.ErrOutOfGas,
ReturnedData: testutils.RandomData(t),
GasConsumed: testutils.RandomGas(1000),
Logs: []*gethTypes.Log{
testutils.GetRandomLogFixture(t),
testutils.GetRandomLogFixture(t),
Expand Down Expand Up @@ -835,7 +835,7 @@ func TestHandler_TransactionRun(t *testing.T) {
result := func(tx *gethTypes.Transaction) *types.Result {
return &types.Result{
DeployedContractAddress: &addr,
ReturnedValue: testutils.RandomData(t),
ReturnedData: testutils.RandomData(t),
GasConsumed: gasConsumed,
TxHash: tx.Hash(),
Logs: []*gethTypes.Log{
Expand Down Expand Up @@ -944,7 +944,7 @@ func TestHandler_TransactionRun(t *testing.T) {
result := func() *types.Result {
return &types.Result{
DeployedContractAddress: &addr,
ReturnedValue: testutils.RandomData(t),
ReturnedData: testutils.RandomData(t),
GasConsumed: gasConsumed,
Logs: []*gethTypes.Log{
testutils.GetRandomLogFixture(t),
Expand Down Expand Up @@ -1008,7 +1008,7 @@ func TestHandler_TransactionRun(t *testing.T) {
addr := testutils.RandomAddress(t)
result := &types.Result{
DeployedContractAddress: &addr,
ReturnedValue: testutils.RandomData(t),
ReturnedData: testutils.RandomData(t),
GasConsumed: testutils.RandomGas(1000),
Logs: []*gethTypes.Log{
testutils.GetRandomLogFixture(t),
Expand Down Expand Up @@ -1055,8 +1055,8 @@ func TestHandler_TransactionRun(t *testing.T) {
uploaded := make(chan struct{})

result := &types.Result{
TxHash: txID,
ReturnedValue: testutils.RandomData(t),
TxHash: txID,
ReturnedData: testutils.RandomData(t),
Logs: []*gethTypes.Log{
testutils.GetRandomLogFixture(t),
},
Expand Down Expand Up @@ -1123,8 +1123,8 @@ func TestHandler_TransactionRun(t *testing.T) {

uploaded := make(chan struct{})
result := &types.Result{
TxHash: gethCommon.HexToHash("0x1"),
ReturnedValue: testutils.RandomData(t),
TxHash: gethCommon.HexToHash("0x1"),
ReturnedData: testutils.RandomData(t),
Logs: []*gethTypes.Log{
testutils.GetRandomLogFixture(t),
},
Expand Down
4 changes: 2 additions & 2 deletions fvm/evm/stdlib/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ func NewResultValue(
},
{
Name: "data",
Value: interpreter.ByteSliceToByteArrayValue(inter, result.ReturnedValue),
Value: interpreter.ByteSliceToByteArrayValue(inter, result.ReturnedData),
},
{
Name: "deployedContract",
Expand Down Expand Up @@ -2372,7 +2372,7 @@ func ResultSummaryFromEVMResultValue(val cadence.Value) (*types.ResultSummary, e
ErrorCode: types.ErrorCode(errorCode),
ErrorMessage: string(errorMsg),
GasConsumed: uint64(gasUsed),
ReturnedValue: convertedData,
ReturnedData: convertedData,
DeployedContractAddress: convertedDeployedAddress,
}, nil

Expand Down
6 changes: 3 additions & 3 deletions fvm/evm/stdlib/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3489,8 +3489,8 @@ func TestCadenceOwnedAccountCall(t *testing.T) {
assert.Equal(t, types.NewBalanceFromUFix64(expectedBalance), balance)

return &types.ResultSummary{
Status: types.StatusSuccessful,
ReturnedValue: types.Data{3, 1, 4},
Status: types.StatusSuccessful,
ReturnedData: types.Data{3, 1, 4},
}
},
}
Expand Down Expand Up @@ -4034,7 +4034,7 @@ func TestCadenceOwnedAccountDeploy(t *testing.T) {
return &types.ResultSummary{
Status: types.StatusSuccessful,
DeployedContractAddress: &types.Address{4},
ReturnedValue: types.Data{5},
ReturnedData: types.Data{5},
}
},
}
Expand Down
2 changes: 1 addition & 1 deletion fvm/evm/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (p *transactionEvent) ToCadence(location common.Location) (cadence.Event, e
cadence.NewUInt64(p.BlockHeight),
cadence.String(p.BlockHash.String()),
cadence.String(errorMsg),
cadence.String(hex.EncodeToString(p.Result.ReturnedValue)),
cadence.String(hex.EncodeToString(p.Result.ReturnedData)),
}).WithType(eventType), nil
}

Expand Down
6 changes: 3 additions & 3 deletions fvm/evm/types/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestEVMTransactionExecutedEventCCFEncodingDecoding(t *testing.T) {
TxType: 255,
GasConsumed: 23200,
DeployedContractAddress: &deployedAddress,
ReturnedValue: dataBytes,
ReturnedData: dataBytes,
Logs: []*gethTypes.Log{log},
TxHash: txHash,
}
Expand All @@ -134,7 +134,7 @@ func TestEVMTransactionExecutedEventCCFEncodingDecoding(t *testing.T) {
assert.Equal(t, tep.TransactionType, txResult.TxType)
assert.Equal(t, tep.GasConsumed, txResult.GasConsumed)
assert.Equal(t, tep.ErrorMessage, txResult.VMError.Error())
assert.Equal(t, tep.ReturnedData, hex.EncodeToString(txResult.ReturnedValue))
assert.Equal(t, tep.ReturnedData, hex.EncodeToString(txResult.ReturnedData))
assert.Equal(
t,
tep.ContractAddress,
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestEVMTransactionExecutedEventCCFEncodingDecoding(t *testing.T) {
assert.Equal(t, tep.TransactionType, txResult.TxType)
assert.Equal(t, tep.GasConsumed, txResult.GasConsumed)
assert.Empty(t, tep.ErrorMessage)
assert.Equal(t, tep.ReturnedData, hex.EncodeToString(txResult.ReturnedValue))
assert.Equal(t, tep.ReturnedData, hex.EncodeToString(txResult.ReturnedData))
assert.NotNil(t, txResult.DeployedContractAddress)
assert.Equal(
t,
Expand Down
8 changes: 4 additions & 4 deletions fvm/evm/types/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ResultSummary struct {
ErrorMessage string
GasConsumed uint64
DeployedContractAddress *Address
ReturnedValue Data
ReturnedData Data
}

// NewInvalidResult creates a new result that hold transaction validation
Expand Down Expand Up @@ -73,8 +73,8 @@ type Result struct {
GasConsumed uint64
// the address where the contract is deployed (if any)
DeployedContractAddress *Address
// returned value from a function call
ReturnedValue []byte
// returned data from a function call
ReturnedData []byte
// EVM logs (events that are emited by evm)
Logs []*gethTypes.Log
// TX hash holdes the cached value of tx hash
Expand Down Expand Up @@ -143,7 +143,7 @@ func (res *Result) ResultSummary() *ResultSummary {
rs := &ResultSummary{
GasConsumed: res.GasConsumed,
DeployedContractAddress: res.DeployedContractAddress,
ReturnedValue: res.ReturnedValue,
ReturnedData: res.ReturnedData,
Status: StatusSuccessful,
}

Expand Down

0 comments on commit ddc729d

Please sign in to comment.