Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

w3vm: Added Receipt.GasRefund #102

Merged
merged 2 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions w3vm/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ var ErrMissingFunc = errors.New("missing function")
type Receipt struct {
f w3types.Func // Func of corresponding message

GasUsed uint64 // Gas used by the message
GasLimit uint64 // Minimum required gas limit (gas used without refund)
GasUsed uint64 // Gas used for executing the message
GasRefund uint64 // Gas refunded after executing the message
GasLimit uint64 // Deprecated: Minimum required gas limit (gas used without refund)
Logs []*types.Log // Logs emitted by the message
Output []byte // Output bytes of the applied message
ContractAddress *common.Address // Contract address created by a contract creation transaction
Expand Down
11 changes: 6 additions & 5 deletions w3vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,12 @@ func (v *VM) apply(msg *w3types.Message, isCall bool, tracer vm.EVMLogger) (*Rec

// build receipt
receipt := &Receipt{
f: msg.Func,
GasUsed: result.UsedGas,
GasLimit: result.UsedGas + v.db.GetRefund(),
Output: result.ReturnData,
Logs: v.db.GetLogs(txHash, 0, hash0),
f: msg.Func,
GasUsed: result.UsedGas,
GasRefund: result.RefundedGas,
GasLimit: result.UsedGas + v.db.GetRefund(),
Output: result.ReturnData,
Logs: v.db.GetLogs(txHash, 0, hash0),
}

if err := result.Err; err != nil {
Expand Down
7 changes: 4 additions & 3 deletions w3vm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ func TestVMApply(t *testing.T) {
Gas: 100_000,
},
WantReceipt: &w3vm.Receipt{
GasUsed: 38_853,
GasLimit: 58_753,
GasUsed: 38_853,
GasRefund: 9_713,
GasLimit: 58_753,
Logs: []*types.Log{
{
Address: addrWETH,
Expand Down Expand Up @@ -411,7 +412,7 @@ func TestVMApply_Integration(t *testing.T) {
cmpopts.EquateEmpty(),
cmpopts.EquateErrors(),
cmpopts.IgnoreUnexported(w3vm.Receipt{}),
cmpopts.IgnoreFields(w3vm.Receipt{}, "GasLimit", "Output"),
cmpopts.IgnoreFields(w3vm.Receipt{}, "GasRefund", "GasLimit", "Output"),
cmpopts.IgnoreFields(types.Log{}, "BlockHash", "BlockNumber", "TxHash", "TxIndex", "Index"),
); diff != "" {
t.Fatalf("(-want +got)\n%s", diff)
Expand Down
Loading