mirror of
https://github.com/luxfi/precompile.git
synced 2026-09-24 00:26:21 +00:00
slhdsa 97.9 · mlkem 97.4 · mldsa 96.8 · xwing 96.2 · bls12381 97.2 · kzg4844 97.8 · v3 98.7. All build, vet and gofmt clean, all green under -count=1, and preserved here rather than lost to a session limit. v3's lane did report before it died: 78.1% to 98.7%, 70 of 70 mutations caught, four of which survived a first pass and needed tests written. The two that matter are rounding: burn rounding principal UP, and fee growth rounding UP, neither of which any behaviour test could see -- a Q128.128 off-by-one is 2^-128 of a token and floors to zero through every payout path, so it took an exact-value assertion. It also found that a full drain of a pool with overlapping positions REVERTS rather than paying out, because deposits round down once per position while payouts round down once per step over combined liquidity, and floor(a+b) >= floor(a)+floor(b). Custody holds; not one unbacked wei leaves. Liveness, not theft. The other six carry no report -- their lanes were killed mid-run. Build, vet, gofmt and the suite are all I can vouch for.
91 lines
2.6 KiB
Go
91 lines
2.6 KiB
Go
// Copyright (C) 2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package kzg4844
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/luxfi/precompile/modules"
|
|
"github.com/luxfi/precompile/precompileconfig"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestModule_RegisteredAtTheAdvertisedAddress(t *testing.T) {
|
|
m, ok := modules.GetPrecompileModuleByAddress(ContractAddress)
|
|
require.True(t, ok, "kzg4844 is not registered at %s", ContractAddress)
|
|
require.Equal(t, ConfigKey, m.ConfigKey)
|
|
require.Equal(t, KZG4844Precompile, m.Contract)
|
|
|
|
byKey, ok := modules.GetPrecompileModule(ConfigKey)
|
|
require.True(t, ok)
|
|
require.Equal(t, ContractAddress, byKey.Address)
|
|
}
|
|
|
|
func TestModule_RegisteringTwiceIsRejected(t *testing.T) {
|
|
require.Error(t, modules.RegisterModule(Module))
|
|
}
|
|
|
|
func TestConfig_MakeConfigMatchesKey(t *testing.T) {
|
|
cfg := Module.Configurator.MakeConfig()
|
|
require.IsType(t, &Config{}, cfg)
|
|
require.Equal(t, ConfigKey, cfg.Key())
|
|
}
|
|
|
|
func TestConfig_Timestamp(t *testing.T) {
|
|
var cfg Config
|
|
require.Nil(t, cfg.Timestamp())
|
|
|
|
at := uint64(1700000000)
|
|
cfg.Upgrade.BlockTimestamp = &at
|
|
require.Equal(t, at, *cfg.Timestamp())
|
|
}
|
|
|
|
func TestConfig_IsDisabled(t *testing.T) {
|
|
var cfg Config
|
|
require.False(t, cfg.IsDisabled())
|
|
|
|
cfg.Upgrade.Disable = true
|
|
require.True(t, cfg.IsDisabled())
|
|
}
|
|
|
|
func TestConfig_Equal(t *testing.T) {
|
|
at, other := uint64(10), uint64(11)
|
|
|
|
a := &Config{Upgrade: precompileconfig.Upgrade{BlockTimestamp: &at}}
|
|
same := &Config{Upgrade: precompileconfig.Upgrade{BlockTimestamp: &at}}
|
|
later := &Config{Upgrade: precompileconfig.Upgrade{BlockTimestamp: &other}}
|
|
disabled := &Config{Upgrade: precompileconfig.Upgrade{BlockTimestamp: &at, Disable: true}}
|
|
|
|
require.True(t, a.Equal(same))
|
|
require.False(t, a.Equal(later))
|
|
require.False(t, a.Equal(disabled))
|
|
require.False(t, a.Equal(nil))
|
|
require.False(t, a.Equal(otherConfig{}))
|
|
}
|
|
|
|
// otherConfig is a Config of a different concrete type, which Equal must
|
|
// refuse rather than treat as a match.
|
|
type otherConfig struct{ precompileconfig.Config }
|
|
|
|
func (otherConfig) Key() string { return "not-kzg4844" }
|
|
|
|
func TestConfig_VerifyAndConfigureAreTotal(t *testing.T) {
|
|
cfg := &Config{}
|
|
require.NoError(t, cfg.Verify(nil))
|
|
require.NoError(t, Module.Configurator.Configure(nil, cfg, nil, nil))
|
|
}
|
|
|
|
func TestConfig_JSONRoundTrip(t *testing.T) {
|
|
at := uint64(42)
|
|
in := &Config{Upgrade: precompileconfig.Upgrade{BlockTimestamp: &at}}
|
|
|
|
raw, err := json.Marshal(in)
|
|
require.NoError(t, err)
|
|
|
|
out := Module.Configurator.MakeConfig()
|
|
require.NoError(t, json.Unmarshal(raw, out))
|
|
require.True(t, in.Equal(out))
|
|
}
|