mirror of
https://github.com/luxfi/proto.git
synced 2026-10-30 15:21:09 +00:00
Adds .hanzo/workflows/cicd.yml calling the canonical pipeline and drops the GitHub-hosted workflows it replaces. Lands here because this is where the repo is written — git.hanzo.ai is upstream and github.com is its push mirror, so the same change made on github.com never reaches the runner fleet.
119 lines
2.8 KiB
Go
119 lines
2.8 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package block
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/luxfi/constants"
|
|
"github.com/luxfi/crypto/secp256k1"
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/proto/x/fxs"
|
|
"github.com/luxfi/proto/x/txs"
|
|
lux "github.com/luxfi/utxo"
|
|
"github.com/luxfi/utxo/secp256k1fx"
|
|
)
|
|
|
|
var (
|
|
chainID = ids.GenerateTestID()
|
|
keys = secp256k1.TestKeys()
|
|
assetID = ids.GenerateTestID()
|
|
)
|
|
|
|
func TestInvalidBlock(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
parser, err := NewParser(
|
|
[]fxs.Fx{
|
|
&secp256k1fx.Fx{},
|
|
},
|
|
)
|
|
require.NoError(err)
|
|
|
|
_, err = parser.ParseBlock(nil)
|
|
require.Error(err)
|
|
}
|
|
|
|
func TestStandardBlocks(t *testing.T) {
|
|
// check standard block can be built and parsed
|
|
require := require.New(t)
|
|
|
|
parser, err := NewParser(
|
|
[]fxs.Fx{
|
|
&secp256k1fx.Fx{},
|
|
},
|
|
)
|
|
require.NoError(err)
|
|
|
|
blkTimestamp := time.Now()
|
|
parentID := ids.GenerateTestID()
|
|
height := uint64(2022)
|
|
txs, err := createTestTxs()
|
|
require.NoError(err)
|
|
|
|
standardBlk, err := NewStandardBlock(parentID, height, blkTimestamp, txs)
|
|
require.NoError(err)
|
|
|
|
// parse block
|
|
parsed, err := parser.ParseBlock(standardBlk.Bytes())
|
|
require.NoError(err)
|
|
|
|
// compare content
|
|
require.Equal(standardBlk.ID(), parsed.ID())
|
|
require.Equal(standardBlk.Parent(), parsed.Parent())
|
|
require.Equal(standardBlk.Height(), parsed.Height())
|
|
require.Equal(standardBlk.Bytes(), parsed.Bytes())
|
|
require.Equal(standardBlk.Timestamp(), parsed.Timestamp())
|
|
|
|
require.IsType(&StandardBlock{}, parsed)
|
|
parsedStandardBlk := parsed.(*StandardBlock)
|
|
|
|
require.Equal(txs, parsedStandardBlk.Txs())
|
|
require.Equal(parsed.Txs(), parsedStandardBlk.Txs())
|
|
}
|
|
|
|
func createTestTxs() ([]*txs.Tx, error) {
|
|
countTxs := 1
|
|
testTxs := make([]*txs.Tx, 0, countTxs)
|
|
for i := 0; i < countTxs; i++ {
|
|
// Create the tx
|
|
tx := &txs.Tx{Unsigned: &txs.BaseTx{BaseTx: lux.BaseTx{
|
|
NetworkID: constants.UnitTestID,
|
|
BlockchainID: chainID,
|
|
Outs: []*lux.TransferableOutput{{
|
|
Asset: lux.Asset{ID: assetID},
|
|
Out: &secp256k1fx.TransferOutput{
|
|
Amt: uint64(12345),
|
|
OutputOwners: secp256k1fx.OutputOwners{
|
|
Threshold: 1,
|
|
Addrs: []ids.ShortID{keys[0].PublicKey().Address()},
|
|
},
|
|
},
|
|
}},
|
|
Ins: []*lux.TransferableInput{{
|
|
UTXOID: lux.UTXOID{
|
|
TxID: ids.ID{'t', 'x', 'I', 'D'},
|
|
OutputIndex: 1,
|
|
},
|
|
Asset: lux.Asset{ID: assetID},
|
|
In: &secp256k1fx.TransferInput{
|
|
Amt: uint64(54321),
|
|
Input: secp256k1fx.Input{
|
|
SigIndices: []uint32{2},
|
|
},
|
|
},
|
|
}},
|
|
Memo: []byte{1, 2, 3, 4, 5, 6, 7, 8},
|
|
}}}
|
|
if err := tx.SignSECP256K1Fx([][]*secp256k1.PrivateKey{{keys[0]}}); err != nil {
|
|
return nil, err
|
|
}
|
|
testTxs = append(testTxs, tx)
|
|
}
|
|
return testTxs, nil
|
|
}
|