mirror of
https://github.com/luxfi/utxo.git
synced 2026-10-30 15:13:57 +00:00
Completes the second cut of FINAL_RIP.md. The first cut (a50337a) dropped
the codec.Registry field from each fx's VM interface and the public API
codec.Manager params. This cut removes the remaining test-side residue:
- Strip `linearcodec.NewDefault()` Codec field literals from every TestVM
(the field no longer exists on TestVM).
- Drop the obsolete `TestCredentialSerialize`, `TestTransferInputSerialize`,
and `TestOutputSerialize` tests in secp256k1fx — they asserted the
legacy linearcodec wire-byte format. ZAP-native round-trips are covered
in wire/wire_test.go and the per-fx wire_test.go files.
- `go mod edit -droprequire github.com/luxfi/codec` + tidy — codec is now
indirect-only (transitively required via github.com/luxfi/vm for the
verify.State interface).
Build + test clean across all 11 packages. ZAP-native at the activation
boundary 2025-12-25T16:20:00-08:00.
171 lines
3.3 KiB
Go
171 lines
3.3 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package secp256k1fx
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/vm/components/verify"
|
|
)
|
|
|
|
func TestOutputAmount(t *testing.T) {
|
|
require := require.New(t)
|
|
out := TransferOutput{
|
|
Amt: 1,
|
|
OutputOwners: OutputOwners{
|
|
Locktime: 1,
|
|
Threshold: 1,
|
|
Addrs: []ids.ShortID{
|
|
ids.ShortEmpty,
|
|
},
|
|
},
|
|
}
|
|
require.Equal(uint64(1), out.Amount())
|
|
}
|
|
|
|
func TestOutputVerify(t *testing.T) {
|
|
require := require.New(t)
|
|
out := TransferOutput{
|
|
Amt: 1,
|
|
OutputOwners: OutputOwners{
|
|
Locktime: 1,
|
|
Threshold: 1,
|
|
Addrs: []ids.ShortID{
|
|
ids.ShortEmpty,
|
|
},
|
|
},
|
|
}
|
|
require.NoError(out.Verify())
|
|
}
|
|
|
|
func TestOutputVerifyNil(t *testing.T) {
|
|
require := require.New(t)
|
|
out := (*TransferOutput)(nil)
|
|
err := out.Verify()
|
|
require.ErrorIs(err, ErrNilOutput)
|
|
}
|
|
|
|
func TestOutputVerifyNoValue(t *testing.T) {
|
|
require := require.New(t)
|
|
out := TransferOutput{
|
|
Amt: 0,
|
|
OutputOwners: OutputOwners{
|
|
Locktime: 1,
|
|
Threshold: 1,
|
|
Addrs: []ids.ShortID{
|
|
ids.ShortEmpty,
|
|
},
|
|
},
|
|
}
|
|
err := out.Verify()
|
|
require.ErrorIs(err, ErrNoValueOutput)
|
|
}
|
|
|
|
func TestOutputVerifyUnspendable(t *testing.T) {
|
|
require := require.New(t)
|
|
out := TransferOutput{
|
|
Amt: 1,
|
|
OutputOwners: OutputOwners{
|
|
Locktime: 1,
|
|
Threshold: 2,
|
|
Addrs: []ids.ShortID{
|
|
ids.ShortEmpty,
|
|
},
|
|
},
|
|
}
|
|
err := out.Verify()
|
|
require.ErrorIs(err, ErrOutputUnspendable)
|
|
}
|
|
|
|
func TestOutputVerifyUnoptimized(t *testing.T) {
|
|
require := require.New(t)
|
|
out := TransferOutput{
|
|
Amt: 1,
|
|
OutputOwners: OutputOwners{
|
|
Locktime: 1,
|
|
Threshold: 0,
|
|
Addrs: []ids.ShortID{
|
|
ids.ShortEmpty,
|
|
},
|
|
},
|
|
}
|
|
err := out.Verify()
|
|
require.ErrorIs(err, ErrOutputUnoptimized)
|
|
}
|
|
|
|
func TestOutputVerifyUnsorted(t *testing.T) {
|
|
require := require.New(t)
|
|
out := TransferOutput{
|
|
Amt: 1,
|
|
OutputOwners: OutputOwners{
|
|
Locktime: 1,
|
|
Threshold: 1,
|
|
Addrs: []ids.ShortID{
|
|
{1},
|
|
{0},
|
|
},
|
|
},
|
|
}
|
|
err := out.Verify()
|
|
require.ErrorIs(err, ErrAddrsNotSortedUnique)
|
|
}
|
|
|
|
func TestOutputVerifyDuplicated(t *testing.T) {
|
|
require := require.New(t)
|
|
out := TransferOutput{
|
|
Amt: 1,
|
|
OutputOwners: OutputOwners{
|
|
Locktime: 1,
|
|
Threshold: 1,
|
|
Addrs: []ids.ShortID{
|
|
ids.ShortEmpty,
|
|
ids.ShortEmpty,
|
|
},
|
|
},
|
|
}
|
|
err := out.Verify()
|
|
require.ErrorIs(err, ErrAddrsNotSortedUnique)
|
|
}
|
|
|
|
// Legacy linearcodec wire-format test deleted with the codec rip.
|
|
// ZAP-native wire round-trip is covered in wire_test.go.
|
|
|
|
func TestOutputAddresses(t *testing.T) {
|
|
require := require.New(t)
|
|
out := TransferOutput{
|
|
Amt: 12345,
|
|
OutputOwners: OutputOwners{
|
|
Locktime: 54321,
|
|
Threshold: 1,
|
|
Addrs: []ids.ShortID{
|
|
{
|
|
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
|
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
|
0x10, 0x11, 0x12, 0x13,
|
|
},
|
|
{
|
|
0x14, 0x15, 0x16, 0x17,
|
|
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
|
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
require.NoError(out.Verify())
|
|
require.Equal([][]byte{
|
|
out.Addrs[0].Bytes(),
|
|
out.Addrs[1].Bytes(),
|
|
}, out.Addresses())
|
|
}
|
|
|
|
func TestTransferOutputState(t *testing.T) {
|
|
require := require.New(t)
|
|
intf := interface{}(&TransferOutput{})
|
|
_, ok := intf.(verify.State)
|
|
require.True(ok)
|
|
}
|