Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions ledger/allegra/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ func TestAllegraUtxorpcBlock(t *testing.T) {
assert.NotNil(t, utxorpcBlock, "RPC block is nil")

t.Run("BlockHeader", func(t *testing.T) {
assert.Equal(t, expectedHash, hex.EncodeToString(utxorpcBlock.Header.Hash),
"Block hash mismatch")
assert.Equal(
t,
expectedHash,
hex.EncodeToString(utxorpcBlock.Header.Hash),
"Block hash mismatch",
)

assert.Equal(t, expectedHeight, utxorpcBlock.Header.Height,
"Block height mismatch")
Expand All @@ -129,10 +133,29 @@ func TestAllegraUtxorpcBlock(t *testing.T) {

if len(rpcTxs) > 0 {
firstRpcTx := rpcTxs[0]
assert.NotEmpty(t, firstRpcTx.Hash, "Transaction hash should not be empty")
assert.Greater(t, len(firstRpcTx.Inputs), 0, "Transaction should have inputs")
assert.Greater(t, len(firstRpcTx.Outputs), 0, "Transaction should have outputs")
assert.Greater(t, firstRpcTx.Fee, uint64(0), "Transaction fee should be positive")
assert.NotEmpty(
t,
firstRpcTx.Hash,
"Transaction hash should not be empty",
)
assert.Greater(
t,
len(firstRpcTx.Inputs),
0,
"Transaction should have inputs",
)
assert.Greater(
t,
len(firstRpcTx.Outputs),
0,
"Transaction should have outputs",
)
assert.Greater(
t,
firstRpcTx.Fee,
uint64(0),
"Transaction fee should be positive",
)
}
})
}
4 changes: 3 additions & 1 deletion ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,9 @@ func (o AlonzoTransactionOutput) ToPlutusData() data.PlutusData {
[][2]data.PlutusData{
{
data.NewByteString(nil),
data.NewInteger(new(big.Int).SetUint64(o.OutputAmount.Amount)),
data.NewInteger(
new(big.Int).SetUint64(o.OutputAmount.Amount),
),
},
},
),
Expand Down
48 changes: 40 additions & 8 deletions ledger/alonzo/alonzo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ func TestAlonzoTransactionOutputToPlutusDataCoinOnly(t *testing.T) {
)
tmpData := testTxOut.ToPlutusData()
if !reflect.DeepEqual(tmpData, expectedData) {
t.Fatalf("did not get expected PlutusData\n got: %#v\n wanted: %#v", tmpData, expectedData)
t.Fatalf(
"did not get expected PlutusData\n got: %#v\n wanted: %#v",
tmpData,
expectedData,
)
}
}

Expand Down Expand Up @@ -131,22 +135,38 @@ func TestAlonzoTransactionOutputToPlutusDataCoinAssets(t *testing.T) {
),
},
{
data.NewByteString(test.DecodeHexString("29a8fb8318718bd756124f0c144f56d4b4579dc5edf2dd42d669ac61")),
data.NewByteString(
test.DecodeHexString(
"29a8fb8318718bd756124f0c144f56d4b4579dc5edf2dd42d669ac61",
),
),
data.NewMap(
[][2]data.PlutusData{
{
data.NewByteString(test.DecodeHexString("6675726e697368613239686e")),
data.NewByteString(
test.DecodeHexString(
"6675726e697368613239686e",
),
),
data.NewInteger(big.NewInt(123456)),
},
},
),
},
{
data.NewByteString(test.DecodeHexString("eaf8042c1d8203b1c585822f54ec32c4c1bb4d3914603e2cca20bbd5")),
data.NewByteString(
test.DecodeHexString(
"eaf8042c1d8203b1c585822f54ec32c4c1bb4d3914603e2cca20bbd5",
),
),
data.NewMap(
[][2]data.PlutusData{
{
data.NewByteString(test.DecodeHexString("426f7764757261436f6e63657074733638")),
data.NewByteString(
test.DecodeHexString(
"426f7764757261436f6e63657074733638",
),
),
data.NewInteger(big.NewInt(234567)),
},
},
Expand All @@ -161,7 +181,11 @@ func TestAlonzoTransactionOutputToPlutusDataCoinAssets(t *testing.T) {
)
tmpData := testTxOut.ToPlutusData()
if !reflect.DeepEqual(tmpData, expectedData) {
t.Fatalf("did not get expected PlutusData\n got: %#v\n wanted: %#v", tmpData, expectedData)
t.Fatalf(
"did not get expected PlutusData\n got: %#v\n wanted: %#v",
tmpData,
expectedData,
)
}
}

Expand Down Expand Up @@ -237,10 +261,18 @@ func TestAlonzoRedeemersIter(t *testing.T) {
for key, val := range testRedeemers.Iter() {
expected := expectedOrder[iterIdx]
if !reflect.DeepEqual(key, expected.Key) {
t.Fatalf("did not get expected key: got %#v, wanted %#v", key, expected.Key)
t.Fatalf(
"did not get expected key: got %#v, wanted %#v",
key,
expected.Key,
)
}
if !reflect.DeepEqual(val, expected.Value) {
t.Fatalf("did not get expected value: got %#v, wanted %#v", val, expected.Value)
t.Fatalf(
"did not get expected value: got %#v, wanted %#v",
val,
expected.Value,
)
}
iterIdx++
}
Expand Down
49 changes: 42 additions & 7 deletions ledger/alonzo/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,24 @@ func TestAlonzoBlockUtxorpc(t *testing.T) {
assert.NotNil(t, block, "Parsed block is nil")

assert.NotEmpty(t, block.Hash(), "Block hash should not be empty")
assert.Greater(t, block.BlockNumber(), uint64(0), "Block number should be positive")
assert.Greater(t, block.SlotNumber(), uint64(0), "Slot number should be positive")
assert.Greater(t, len(block.Transactions()), 0, "Block should contain transactions")
assert.Greater(
t,
block.BlockNumber(),
uint64(0),
"Block number should be positive",
)
assert.Greater(
t,
block.SlotNumber(),
uint64(0),
"Slot number should be positive",
)
assert.Greater(
t,
len(block.Transactions()),
0,
"Block should contain transactions",
)

t.Run("UtxorpcConversion", func(t *testing.T) {
pbBlock, err := block.Utxorpc()
Expand All @@ -36,9 +51,29 @@ func TestAlonzoBlockUtxorpc(t *testing.T) {
}

assert.NotNil(t, pbBlock, "Converted block should not be nil")
assert.Equal(t, block.Hash().Bytes(), pbBlock.Header.Hash, "Block hash mismatch")
assert.Equal(t, block.BlockNumber(), pbBlock.Header.Height, "Block height mismatch")
assert.Equal(t, block.SlotNumber(), pbBlock.Header.Slot, "Block slot mismatch")
assert.Equal(t, len(block.Transactions()), len(pbBlock.Body.Tx), "Transaction count mismatch")
assert.Equal(
t,
block.Hash().Bytes(),
pbBlock.Header.Hash,
"Block hash mismatch",
)
assert.Equal(
t,
block.BlockNumber(),
pbBlock.Header.Height,
"Block height mismatch",
)
assert.Equal(
t,
block.SlotNumber(),
pbBlock.Header.Slot,
"Block slot mismatch",
)
assert.Equal(
t,
len(block.Transactions()),
len(pbBlock.Body.Tx),
"Transaction count mismatch",
)
})
}
4 changes: 3 additions & 1 deletion ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,9 @@ func (o BabbageTransactionOutput) ToPlutusData() data.PlutusData {
[][2]data.PlutusData{
{
data.NewByteString(nil),
data.NewInteger(new(big.Int).SetUint64(o.OutputAmount.Amount)),
data.NewInteger(
new(big.Int).SetUint64(o.OutputAmount.Amount),
),
},
},
),
Expand Down
36 changes: 30 additions & 6 deletions ledger/babbage/babbage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2857,7 +2857,11 @@ func TestBabbageTransactionOutputToPlutusDataCoinOnly(t *testing.T) {
)
tmpData := testTxOut.ToPlutusData()
if !reflect.DeepEqual(tmpData, expectedData) {
t.Fatalf("did not get expected PlutusData\n got: %#v\n wanted: %#v", tmpData, expectedData)
t.Fatalf(
"did not get expected PlutusData\n got: %#v\n wanted: %#v",
tmpData,
expectedData,
)
}
}

Expand Down Expand Up @@ -2913,22 +2917,38 @@ func TestBabbageTransactionOutputToPlutusDataCoinAssets(t *testing.T) {
),
},
{
data.NewByteString(test.DecodeHexString("29a8fb8318718bd756124f0c144f56d4b4579dc5edf2dd42d669ac61")),
data.NewByteString(
test.DecodeHexString(
"29a8fb8318718bd756124f0c144f56d4b4579dc5edf2dd42d669ac61",
),
),
data.NewMap(
[][2]data.PlutusData{
{
data.NewByteString(test.DecodeHexString("6675726e697368613239686e")),
data.NewByteString(
test.DecodeHexString(
"6675726e697368613239686e",
),
),
data.NewInteger(big.NewInt(123456)),
},
},
),
},
{
data.NewByteString(test.DecodeHexString("eaf8042c1d8203b1c585822f54ec32c4c1bb4d3914603e2cca20bbd5")),
data.NewByteString(
test.DecodeHexString(
"eaf8042c1d8203b1c585822f54ec32c4c1bb4d3914603e2cca20bbd5",
),
),
data.NewMap(
[][2]data.PlutusData{
{
data.NewByteString(test.DecodeHexString("426f7764757261436f6e63657074733638")),
data.NewByteString(
test.DecodeHexString(
"426f7764757261436f6e63657074733638",
),
),
data.NewInteger(big.NewInt(234567)),
},
},
Expand All @@ -2943,6 +2963,10 @@ func TestBabbageTransactionOutputToPlutusDataCoinAssets(t *testing.T) {
)
tmpData := testTxOut.ToPlutusData()
if !reflect.DeepEqual(tmpData, expectedData) {
t.Fatalf("did not get expected PlutusData\n got: %#v\n wanted: %#v", tmpData, expectedData)
t.Fatalf(
"did not get expected PlutusData\n got: %#v\n wanted: %#v",
tmpData,
expectedData,
)
}
}
36 changes: 30 additions & 6 deletions ledger/babbage/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,38 @@ func TestBabbageBlockUtxorpc(t *testing.T) {
}

if !bytes.Equal(utxoBlock.Header.Hash, hashBytes) {
t.Errorf("unexpected block hash: got %x, want %x", utxoBlock.Header.Hash, hashBytes)
t.Errorf(
"unexpected block hash: got %x, want %x",
utxoBlock.Header.Hash,
hashBytes,
)
}

// Verify block number matches what's in the header body
if utxoBlock.Header.Height != block.BlockHeader.Body.BlockNumber {
t.Errorf("unexpected block height: got %d, want %d", utxoBlock.Header.Height, block.BlockHeader.Body.BlockNumber)
t.Errorf(
"unexpected block height: got %d, want %d",
utxoBlock.Header.Height,
block.BlockHeader.Body.BlockNumber,
)
}

// Verify slot number matches what's in the header body
if utxoBlock.Header.Slot != block.BlockHeader.Body.Slot {
t.Errorf("unexpected block slot: got %d, want %d", utxoBlock.Header.Slot, block.BlockHeader.Body.Slot)
t.Errorf(
"unexpected block slot: got %d, want %d",
utxoBlock.Header.Slot,
block.BlockHeader.Body.Slot,
)
}

// Verify transactions
if len(utxoBlock.Body.Tx) != len(block.TransactionBodies) {
t.Errorf("unexpected transaction count: got %d, want %d", len(utxoBlock.Body.Tx), len(block.TransactionBodies))
t.Errorf(
"unexpected transaction count: got %d, want %d",
len(utxoBlock.Body.Tx),
len(block.TransactionBodies),
)
}

// Verify the first transaction as a sample
Expand All @@ -69,11 +85,19 @@ func TestBabbageBlockUtxorpc(t *testing.T) {
}

if len(tx.Inputs) != len(block.TransactionBodies[0].TxInputs.Items()) {
t.Errorf("unexpected input count in first tx: got %d, want %d", len(tx.Inputs), len(block.TransactionBodies[0].TxInputs.Items()))
t.Errorf(
"unexpected input count in first tx: got %d, want %d",
len(tx.Inputs),
len(block.TransactionBodies[0].TxInputs.Items()),
)
}

if len(tx.Outputs) != len(block.TransactionBodies[0].TxOutputs) {
t.Errorf("unexpected output count in first tx: got %d, want %d", len(tx.Outputs), len(block.TransactionBodies[0].TxOutputs))
t.Errorf(
"unexpected output count in first tx: got %d, want %d",
len(tx.Outputs),
len(block.TransactionBodies[0].TxOutputs),
)
}
}
}
Loading