mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
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.
118 lines
2.6 KiB
Go
118 lines
2.6 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package math
|
|
|
|
import (
|
|
"math"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
const maxUint64 uint64 = math.MaxUint64
|
|
|
|
func TestMaxUint(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
require.Equal(uint(math.MaxUint), MaxUint[uint]())
|
|
require.Equal(uint8(math.MaxUint8), MaxUint[uint8]())
|
|
require.Equal(uint16(math.MaxUint16), MaxUint[uint16]())
|
|
require.Equal(uint32(math.MaxUint32), MaxUint[uint32]())
|
|
require.Equal(uint64(math.MaxUint64), MaxUint[uint64]())
|
|
require.Equal(uintptr(math.MaxUint), MaxUint[uintptr]())
|
|
}
|
|
|
|
func TestAdd(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
sum, err := Add(0, maxUint64)
|
|
require.NoError(err)
|
|
require.Equal(maxUint64, sum)
|
|
|
|
sum, err = Add(maxUint64, 0)
|
|
require.NoError(err)
|
|
require.Equal(maxUint64, sum)
|
|
|
|
sum, err = Add(uint64(1<<62), uint64(1<<62))
|
|
require.NoError(err)
|
|
require.Equal(uint64(1<<63), sum)
|
|
|
|
_, err = Add(1, maxUint64)
|
|
require.ErrorIs(err, ErrOverflow)
|
|
|
|
_, err = Add(maxUint64, 1)
|
|
require.ErrorIs(err, ErrOverflow)
|
|
|
|
_, err = Add(maxUint64, maxUint64)
|
|
require.ErrorIs(err, ErrOverflow)
|
|
}
|
|
|
|
func TestSub(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
got, err := Sub(uint64(2), uint64(1))
|
|
require.NoError(err)
|
|
require.Equal(uint64(1), got)
|
|
|
|
got, err = Sub(uint64(2), uint64(2))
|
|
require.NoError(err)
|
|
require.Zero(got)
|
|
|
|
got, err = Sub(maxUint64, maxUint64)
|
|
require.NoError(err)
|
|
require.Zero(got)
|
|
|
|
got, err = Sub(uint64(3), uint64(2))
|
|
require.NoError(err)
|
|
require.Equal(uint64(1), got)
|
|
|
|
_, err = Sub(uint64(1), uint64(2))
|
|
require.ErrorIs(err, ErrUnderflow)
|
|
|
|
_, err = Sub(maxUint64-1, maxUint64)
|
|
require.ErrorIs(err, ErrUnderflow)
|
|
}
|
|
|
|
func TestMul(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
got, err := Mul(0, maxUint64)
|
|
require.NoError(err)
|
|
require.Zero(got)
|
|
|
|
got, err = Mul(maxUint64, 0)
|
|
require.NoError(err)
|
|
require.Zero(got)
|
|
|
|
got, err = Mul(uint64(1), uint64(3))
|
|
require.NoError(err)
|
|
require.Equal(uint64(3), got)
|
|
|
|
got, err = Mul(uint64(3), uint64(1))
|
|
require.NoError(err)
|
|
require.Equal(uint64(3), got)
|
|
|
|
got, err = Mul(uint64(2), uint64(3))
|
|
require.NoError(err)
|
|
require.Equal(uint64(6), got)
|
|
|
|
got, err = Mul(maxUint64, 0)
|
|
require.NoError(err)
|
|
require.Zero(got)
|
|
|
|
_, err = Mul(maxUint64-1, 2)
|
|
require.ErrorIs(err, ErrOverflow)
|
|
}
|
|
|
|
func TestAbsDiff(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
require.Equal(maxUint64, AbsDiff(0, maxUint64))
|
|
require.Equal(maxUint64, AbsDiff(maxUint64, 0))
|
|
require.Equal(uint64(2), AbsDiff(uint64(3), uint64(1)))
|
|
require.Equal(uint64(2), AbsDiff(uint64(1), uint64(3)))
|
|
require.Zero(AbsDiff(uint64(1), uint64(1)))
|
|
require.Zero(AbsDiff(uint64(0), uint64(0)))
|
|
}
|