Files
zeekay 7cf87b230b node-unified is the node
The module already called itself github.com/luxfi/node while containing no node
in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and
the Go column of the matrix measured a VM plugin. A repo that fetches the thing
it claims to be has not replaced it, so the Go sources move in — 1515 files,
the daemon and everything under it — and the build reaches outside this module
for nothing.

Rust and C++ sit beside it unchanged and are still measured against it by the
differential. That is the point of one repo: the reference implementation and
the two ports are the same checkout, so parity is a thing you can run rather
than a thing you assert.

Verified: builds, and the closure carries no lux-private — checked at build time
rather than believed. The daemon starts twelve chains on a local network
(P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
2026-09-07 16:15:25 -07:00

193 lines
4.5 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package gas
import (
"fmt"
"math"
"testing"
"github.com/stretchr/testify/require"
)
var calculatePriceTests = []struct {
minPrice Price
excess Gas
excessConversionConstant Gas
expected Price
}{
{
minPrice: 1,
excess: 0,
excessConversionConstant: 1,
expected: 1,
},
{
minPrice: 1,
excess: 1,
excessConversionConstant: 1,
expected: 2,
},
{
minPrice: 1,
excess: 2,
excessConversionConstant: 1,
expected: 6,
},
{
minPrice: 1,
excess: 10_000,
excessConversionConstant: 10_000,
expected: 2,
},
{
minPrice: 1,
excess: 1_000_000,
excessConversionConstant: 10_000,
expected: math.MaxUint64,
},
{
minPrice: 10,
excess: 10_000_000,
excessConversionConstant: 1_000_000,
expected: 220_264,
},
{
minPrice: math.MaxUint64,
excess: math.MaxUint64,
excessConversionConstant: 1,
expected: math.MaxUint64,
},
{
minPrice: math.MaxUint32,
excess: 1,
excessConversionConstant: 1,
expected: 11_674_931_546,
},
{
minPrice: 6_786_177_901_268_885_274, // ~ MaxUint64 / e
excess: 1,
excessConversionConstant: 1,
expected: math.MaxUint64 - 11,
},
{
minPrice: 6_786_177_901_268_885_274, // ~ MaxUint64 / e
excess: math.MaxUint64,
excessConversionConstant: math.MaxUint64,
expected: math.MaxUint64 - 1,
},
}
func Test_Gas_Cost(t *testing.T) {
require := require.New(t)
const (
gas Gas = 40
price Price = 100
expected uint64 = 4000
)
actual, err := gas.Cost(price)
require.NoError(err)
require.Equal(expected, actual)
}
func Test_Gas_AddPerSecond(t *testing.T) {
tests := []struct {
initial Gas
gasPerSecond Gas
seconds uint64
expected Gas
}{
{
initial: 5,
gasPerSecond: 1,
seconds: 2,
expected: 7,
},
{
initial: 5,
gasPerSecond: math.MaxUint64,
seconds: 2,
expected: math.MaxUint64,
},
{
initial: math.MaxUint64,
gasPerSecond: 1,
seconds: 2,
expected: math.MaxUint64,
},
{
initial: math.MaxUint64,
gasPerSecond: math.MaxUint64,
seconds: math.MaxUint64,
expected: math.MaxUint64,
},
}
for _, test := range tests {
t.Run(fmt.Sprintf("%d+%d*%d=%d", test.initial, test.gasPerSecond, test.seconds, test.expected), func(t *testing.T) {
actual := test.initial.AddPerSecond(test.gasPerSecond, test.seconds)
require.Equal(t, test.expected, actual)
})
}
}
func Test_Gas_SubPerSecond(t *testing.T) {
tests := []struct {
initial Gas
gasPerSecond Gas
seconds uint64
expected Gas
}{
{
initial: 5,
gasPerSecond: 1,
seconds: 2,
expected: 3,
},
{
initial: 5,
gasPerSecond: math.MaxUint64,
seconds: 2,
expected: 0,
},
{
initial: 1,
gasPerSecond: 1,
seconds: 2,
expected: 0,
},
{
initial: math.MaxUint64,
gasPerSecond: math.MaxUint64,
seconds: math.MaxUint64,
expected: 0,
},
}
for _, test := range tests {
t.Run(fmt.Sprintf("%d-%d*%d=%d", test.initial, test.gasPerSecond, test.seconds, test.expected), func(t *testing.T) {
actual := test.initial.SubPerSecond(test.gasPerSecond, test.seconds)
require.Equal(t, test.expected, actual)
})
}
}
func Test_CalculatePrice(t *testing.T) {
for _, test := range calculatePriceTests {
t.Run(fmt.Sprintf("%d*e^(%d/%d)=%d", test.minPrice, test.excess, test.excessConversionConstant, test.expected), func(t *testing.T) {
actual := CalculatePrice(test.minPrice, test.excess, test.excessConversionConstant)
require.Equal(t, test.expected, actual)
})
}
}
func Benchmark_CalculatePrice(b *testing.B) {
for _, test := range calculatePriceTests {
b.Run(fmt.Sprintf("%d*e^(%d/%d)=%d", test.minPrice, test.excess, test.excessConversionConstant, test.expected), func(b *testing.B) {
for i := 0; i < b.N; i++ {
CalculatePrice(test.minPrice, test.excess, test.excessConversionConstant)
}
})
}
}