mirror of
https://github.com/luxfi/sdk.git
synced 2026-10-30 15:19:23 +00:00
github.com/luxfi/codec is gone from this module — no import, no call, no require. Nothing here marshals or unmarshals a transaction any more. WHY IT BROKE. codec deleted its jsonrpc subpackage (1b67d6a, "delete dead subpackages") while nine files imported it. It looked dead because the PUBLISHED [email protected] still ships it, so only a workspace build — which resolves codec from the local checkout — ever saw the break. THE WIRE. A tx already carries its own ZAP encoding, so the codec was re-deriving what the tx could hand over: txs.Codec.Marshal(txs.CodecVersion, &tx.Unsigned) -> tx.Unsigned.Bytes() txs.UnsignedBytes(tx.Unsigned) txs.Codec.Marshal(txs.CodecVersion, tx) -> tx.Initialize() txs.Codec.Unmarshal(txBytes, &tx) -> txs.Parse(txBytes) codec.Unmarshal(utxoBytes, &utxo) -> utxo.ParseUTXO(...) These are the same calls the node makes in txs.Tx.Sign. AddAllUTXOs no longer takes a codec.Manager, and SortTransferableOutputs / state.Sort / SortOperations no longer get one — upstream dropped the parameter. PARALLEL IMPLEMENTATIONS, DELETED. wallet/chain/{p,x} carried a second copy of the builder and signer beside the subpackages that already held them — p/signer_visitor.go and p/signer/visitor.go were both 399 lines of the same thing, and each defect had to be fixed twice. The flat files are gone; the package keeps the facade it already had in wallet_exports.go, which re-exports the subpackage. -4787 lines. wallet/chain/c is deleted. Its whole reason to exist was a codec.Manager scaffold for C-chain atomic-tx wire that nothing runs: NewWallet was passed nil for it, and the builder was commented out. The two symbols anything used move to where they are read — Account, a balance and a nonce off an EVM client, and EVMKeychain, the geth-address half of a keychain. Wallet no longer advertises a C() that only ever returned nil. ALIGNED. XAssetID -> UTXOAssetID, matching runtime.Runtime and netrunner, which already expected it. Keychain GetEth -> GetByEVM, EthAddrs -> EVMAddrs. warp UnsignedMessage and Message collapsed into one flat Message, so a signature is an Envelope rather than a second message type. netrunner's HealthResponse is read as a field: the getter form is protobuf, behind //go:build grpc, and the default build is ZAP-native. VERIFIED on a machine with the native libraries: go build ./... exits 0 with no codec require in go.mod, and go test ./... is 23 ok. Three packages still fail to build their tests — profiles, wallet/keychain, wallet/primary — and all three fail identically on the tree before this change: Consensus, VerifyHybridSecp256k1MLDSA and isXChainNotEnabled are referenced by tests and defined nowhere. evm failed there too and now passes.
157 lines
4.5 KiB
Go
157 lines
4.5 KiB
Go
// Copyright (C) 2025, Lux Industries Inc All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
package evm
|
|
|
|
import (
|
|
"testing"
|
|
|
|
evmwarp "github.com/luxfi/evm/precompile/contracts/warp"
|
|
"github.com/luxfi/geth/common"
|
|
"github.com/luxfi/geth/core/types"
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/warp"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGetWarpMessagesFromLogs(t *testing.T) {
|
|
// Test case 1: Empty logs
|
|
logs := []*types.Log{}
|
|
messages := GetWarpMessagesFromLogs(logs)
|
|
require.Empty(t, messages)
|
|
// Test case 2: Log with invalid warp message
|
|
invalidPayload := []byte{1, 2, 3, 4, 5}
|
|
invalidLog := &types.Log{
|
|
Data: invalidPayload,
|
|
}
|
|
logs = []*types.Log{invalidLog}
|
|
messages = GetWarpMessagesFromLogs(logs)
|
|
require.Empty(t, messages)
|
|
// Test case 3: Log with valid warp message
|
|
chainID := ids.ID{}
|
|
unsignedWarpMessage, err := warp.NewMessage(
|
|
0,
|
|
chainID,
|
|
[]byte{},
|
|
)
|
|
require.NoError(t, err)
|
|
_, validPayload, err := evmwarp.PackSendWarpMessageEvent(
|
|
common.Address{},
|
|
common.Hash{},
|
|
unsignedWarpMessage.Bytes(),
|
|
)
|
|
require.NoError(t, err)
|
|
validLog := &types.Log{
|
|
Data: validPayload,
|
|
}
|
|
logs = []*types.Log{validLog}
|
|
messages = GetWarpMessagesFromLogs(logs)
|
|
require.Equal(t, messages, []*warp.Message{unsignedWarpMessage})
|
|
// Test case 4: Multiple logs with mixed valid and invalid messages
|
|
logs = []*types.Log{validLog, invalidLog}
|
|
messages = GetWarpMessagesFromLogs(logs)
|
|
require.Equal(t, messages, []*warp.Message{unsignedWarpMessage})
|
|
}
|
|
|
|
func TestExtractWarpMessageFromLogs(t *testing.T) {
|
|
// Test case 1: Empty logs
|
|
logs := []*types.Log{}
|
|
msg, err := ExtractWarpMessageFromLogs(logs)
|
|
require.Error(t, err)
|
|
require.Nil(t, msg)
|
|
require.Contains(t, err.Error(), "no warp message is present in evm logs")
|
|
// Test case 2: Log with invalid warp message
|
|
invalidPayload := []byte{1, 2, 3, 4, 5}
|
|
invalidLog := &types.Log{
|
|
Data: invalidPayload,
|
|
}
|
|
logs = []*types.Log{invalidLog}
|
|
msg, err = ExtractWarpMessageFromLogs(logs)
|
|
require.Error(t, err)
|
|
require.Nil(t, msg)
|
|
require.Contains(t, err.Error(), "no warp message is present in evm logs")
|
|
// Test case 3: Log with valid warp message
|
|
chainID := ids.ID{}
|
|
unsignedWarpMessage, err := warp.NewMessage(
|
|
0,
|
|
chainID,
|
|
[]byte{},
|
|
)
|
|
require.NoError(t, err)
|
|
_, validPayload, err := evmwarp.PackSendWarpMessageEvent(
|
|
common.Address{},
|
|
common.Hash{},
|
|
unsignedWarpMessage.Bytes(),
|
|
)
|
|
require.NoError(t, err)
|
|
validLog := &types.Log{
|
|
Data: validPayload,
|
|
}
|
|
logs = []*types.Log{validLog}
|
|
msg, err = ExtractWarpMessageFromLogs(logs)
|
|
require.NoError(t, err)
|
|
require.Equal(t, unsignedWarpMessage, msg)
|
|
// Test case 4: Multiple logs with mixed valid and invalid messages
|
|
logs = []*types.Log{validLog, invalidLog}
|
|
msg, err = ExtractWarpMessageFromLogs(logs)
|
|
require.NoError(t, err)
|
|
require.Equal(t, unsignedWarpMessage, msg)
|
|
}
|
|
|
|
func TestExtractWarpMessageFromReceipt(t *testing.T) {
|
|
// Test case 1: Nil receipt
|
|
msg, err := ExtractWarpMessageFromReceipt(nil)
|
|
require.Error(t, err)
|
|
require.Nil(t, msg)
|
|
require.Contains(t, err.Error(), "empty receipt was given")
|
|
// Test case 2: Receipt with empty logs
|
|
emptyReceipt := &types.Receipt{
|
|
Logs: []*types.Log{},
|
|
}
|
|
msg, err = ExtractWarpMessageFromReceipt(emptyReceipt)
|
|
require.Error(t, err)
|
|
require.Nil(t, msg)
|
|
require.Contains(t, err.Error(), "no warp message is present in evm logs")
|
|
// Test case 3: Receipt with invalid warp message
|
|
invalidPayload := []byte{1, 2, 3, 4, 5}
|
|
invalidLog := &types.Log{
|
|
Data: invalidPayload,
|
|
}
|
|
invalidReceipt := &types.Receipt{
|
|
Logs: []*types.Log{invalidLog},
|
|
}
|
|
msg, err = ExtractWarpMessageFromReceipt(invalidReceipt)
|
|
require.Error(t, err)
|
|
require.Nil(t, msg)
|
|
require.Contains(t, err.Error(), "no warp message is present in evm logs")
|
|
// Test case 4: Receipt with valid warp message
|
|
chainID2 := ids.ID{}
|
|
unsignedWarpMessage, err := warp.NewMessage(
|
|
0,
|
|
chainID2,
|
|
[]byte{},
|
|
)
|
|
require.NoError(t, err)
|
|
_, validPayload, err := evmwarp.PackSendWarpMessageEvent(
|
|
common.Address{},
|
|
common.Hash{},
|
|
unsignedWarpMessage.Bytes(),
|
|
)
|
|
require.NoError(t, err)
|
|
validLog := &types.Log{
|
|
Data: validPayload,
|
|
}
|
|
validReceipt := &types.Receipt{
|
|
Logs: []*types.Log{validLog},
|
|
}
|
|
msg, err = ExtractWarpMessageFromReceipt(validReceipt)
|
|
require.NoError(t, err)
|
|
require.Equal(t, unsignedWarpMessage, msg)
|
|
// Test case 5: Receipt with multiple logs (valid and invalid)
|
|
mixedReceipt := &types.Receipt{
|
|
Logs: []*types.Log{validLog, invalidLog},
|
|
}
|
|
msg, err = ExtractWarpMessageFromReceipt(mixedReceipt)
|
|
require.NoError(t, err)
|
|
require.Equal(t, unsignedWarpMessage, msg)
|
|
}
|