Files
chains/relayvm/feegate_test.go
T
zeekay ec074f11aa evm, oraclevm, relayvm: a vmID nobody compared, and a policy no rollback could reach
The two shims re-exported luxfi/oracle's and luxfi/relay's private vmID
literals. constants.OracleVMID and constants.RelayVMID exist, agree with them,
and nothing made them agree. This repo builds the plugin binary whose FILENAME
is that id, so the shims now name the constant and their tests compare all
three; a drift upstream fails here instead of producing a chain no node starts.

cevm gets ErrNotLinked, so a caller can tell "this build has no C++ EVM" from
"this input is bad". cevm/parallel's sender-recovery step returned a hard error
for the first, which in a build without the library is every block, forever,
and CEVM_STRICT=0 -- the documented rollback to the Go EVM -- did not reach
that line. It now leaves by declineBlock like every other capability refusal.

Its receipt gate asked whether a transaction carried calldata. A contract
creation with empty init code carries none, so it was receipted as a value
transfer: no ContractAddress, and 21000 intrinsic gas against creation's 53000,
into the cumulative total the header commits to.

ExecuteBlock splits into shape / dispatch / assemble so the parity-critical
half needs no library to exercise. strictGPUEVM loses the sync.Once that fixed
its answer at the first decline and left both branches unreachable from one
process.

The native build referenced gpu_execute_block and gpu_free_result, which ABI v6
removed, so nothing behind lux_cevm_native compiled at all.

The three plugins print the version the VM reports rather than a second literal
beside it, and the vmID the binary must be installed under: a plugin under the
wrong filename is invisible and the chain simply never appears.

cevm/plugin.go is gone. It located a binary at ~/work/luxcpp/evm/build/bin/cevm,
a path that has never existed -- the tree is luxcpp/cevm -- claimed the lux CLI
and universe Makefiles used it, which neither does, and returned "cevm" from a
function called VMID. Its two tests skipped and asserted nothing.

.gitignore's bare `plugin` matched every <vm>/cmd/plugin DIRECTORY, so a new
file under one could not be added: git printed a hint and staged nothing.
mpcvm's and bridgevm's plugin tests are written, pass, and are not in the
repository.

Coverage: evm 0.0 -> 85.0, evm/cevm 71.1 -> 100.0, evm/cevm/parallel 0.0 -> 86.1,
oraclevm 0.0 -> 90.0, oraclevm/cmd/plugin 0.0 -> 72.2, relayvm/cmd/plugin 0.0 -> 72.2.
2026-08-28 15:01:34 -07:00

93 lines
2.9 KiB
Go

// Copyright (C) 2019-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package relayvm
import (
"context"
"encoding/json"
"testing"
"github.com/luxfi/database/memdb"
"github.com/luxfi/ids"
"github.com/luxfi/log"
"github.com/luxfi/node/vms/types/fee"
"github.com/luxfi/runtime"
vmcore "github.com/luxfi/vm"
"github.com/luxfi/vm/chain"
)
// feegate.go states that a caller constructing a VM through this shim
// "transitively gets the NoUserTxPolicy{}". That is a claim about a value in
// another repo, held here only in prose.
//
// luxfi/relay's own feegate test builds `&VM{feePolicy: fee.NoUserTxPolicy{}}`
// — it assigns the field it then reads, so it passes unchanged if Initialize
// stops pinning the policy. This starts from the Factory the node uses, runs
// the real Initialize, and reads the policy back. It is the shim's claim, so
// it is the shim's test.
func TestAVMBuiltThroughThisShimTakesNoUserTransactions(t *testing.T) {
vm := start(t)
policy := vm.FeePolicy()
if policy == nil {
t.Fatal("FeePolicy() = nil; a chain that declares no policy is a chain with no declared cost")
}
if _, ok := policy.(fee.NoUserTxPolicy); !ok {
t.Fatalf("FeePolicy() = %T, want fee.NoUserTxPolicy — R-Chain is service-only, "+
"relayed messages arrive through consensus and there is no user mempool", policy)
}
if err := fee.Validate(policy); err != nil {
t.Fatalf("the node's boot gate rejects R-Chain's own declaration: %v", err)
}
}
// An uninitialized VM has not declared anything, and the shim's claim is about
// initialized VMs only. Pinned so the test above cannot be read as "any *VM
// refuses" — it is Initialize that pins the policy, and that is the statement.
func TestAnUninitializedVMHasNoPolicy(t *testing.T) {
raw, err := (&Factory{}).New(log.Root())
if err != nil {
t.Fatalf("Factory.New: %v", err)
}
if policy := raw.(*VM).FeePolicy(); policy != nil {
t.Fatalf("a VM that never ran Initialize reports policy %T; the policy is "+
"pinned by Initialize and nowhere else", policy)
}
}
// start builds a VM the way the node does — through the Factory — and runs
// Initialize against an in-memory database.
func start(t *testing.T) *VM {
t.Helper()
raw, err := (&Factory{}).New(log.Root())
if err != nil {
t.Fatalf("Factory.New: %v", err)
}
vm := raw.(*VM)
genesis, err := json.Marshal(Genesis{})
if err != nil {
t.Fatalf("marshal genesis: %v", err)
}
init := vmcore.Init{
Runtime: &runtime.Runtime{
ChainID: ids.GenerateTestID(),
Log: log.NewNoOpLogger(),
},
DB: memdb.New(),
Genesis: genesis,
ToEngine: make(chan vmcore.Message, 1),
}
if err := vm.Initialize(context.Background(), init); err != nil {
t.Fatalf("Initialize: %v", err)
}
t.Cleanup(func() { _ = vm.Shutdown(context.Background()) })
// Initialize is the ChainVM contract's entry point, so what it returns must
// still be the thing the plugin serves.
var _ chain.ChainVM = vm
return vm
}