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
6 changes: 5 additions & 1 deletion internal/test/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ func (ls MockLedgerState) PoolCurrentState(
poolKeyHash []byte,
) (*common.PoolRegistrationCertificate, *uint64, error) {
for _, cert := range ls.MockPoolRegistration {
if string(common.Blake2b224(cert.Operator).Bytes()) == string(poolKeyHash) {
if string(
common.Blake2b224(cert.Operator).Bytes(),
) == string(
poolKeyHash,
) {
// pretend latest registration is current; no retirement support in mock
c := cert
return &c, nil, nil
Expand Down
5 changes: 4 additions & 1 deletion ledger/allegra/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,10 @@ func TestAllegraTransactionBody_Utxorpc(t *testing.T) {
// Run Utxorpc conversion
actual, err := txBody.Utxorpc()
if err != nil {
t.Fatalf("Could not convert transaction body to utxorpc format: %v", err)
t.Fatalf(
"Could not convert transaction body to utxorpc format: %v",
err,
)
}

// Check that the fee matches
Expand Down
9 changes: 7 additions & 2 deletions ledger/alonzo/alonzo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,17 @@ func TestAlonzoTransactionOutputString(t *testing.T) {
addr, _ := common.NewAddress(addrStr)
ma := common.NewMultiAsset[common.MultiAssetTypeOutput](
map[common.Blake2b224]map[cbor.ByteString]uint64{
common.NewBlake2b224(make([]byte, 28)): {cbor.NewByteString([]byte("t")): 2},
common.NewBlake2b224(make([]byte, 28)): {
cbor.NewByteString([]byte("t")): 2,
},
},
)
out := AlonzoTransactionOutput{
OutputAddress: addr,
OutputAmount: mary.MaryTransactionOutputValue{Amount: 456, Assets: &ma},
OutputAmount: mary.MaryTransactionOutputValue{
Amount: 456,
Assets: &ma,
},
}
s := out.String()
policyStr := common.NewBlake2b224(make([]byte, 28)).String()
Expand Down
8 changes: 6 additions & 2 deletions ledger/alonzo/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ func TestScientificNotationInCostModels(t *testing.T) {
}

expected := []int64{2477736, 1500000, 1000000}
if params.CostModels == nil || params.CostModels[alonzo.PlutusV1Key] == nil {
if params.CostModels == nil ||
params.CostModels[alonzo.PlutusV1Key] == nil {
t.Fatal("CostModels not properly initialized")
}
for i := range 3 {
Expand Down Expand Up @@ -520,7 +521,10 @@ func TestAlonzoTransactionBody_Utxorpc(t *testing.T) {
// Run Utxorpc conversion
got, err := body.Utxorpc()
if err != nil {
t.Fatalf("Could not convert transaction body to utxorpc format: %v", err)
t.Fatalf(
"Could not convert transaction body to utxorpc format: %v",
err,
)
}

// Assertion checks
Expand Down
9 changes: 7 additions & 2 deletions ledger/babbage/babbage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2976,12 +2976,17 @@ func TestBabbageTransactionOutputString(t *testing.T) {
addr, _ := common.NewAddress(addrStr)
ma := common.NewMultiAsset[common.MultiAssetTypeOutput](
map[common.Blake2b224]map[cbor.ByteString]uint64{
common.NewBlake2b224(make([]byte, 28)): {cbor.NewByteString([]byte("x")): 2},
common.NewBlake2b224(make([]byte, 28)): {
cbor.NewByteString([]byte("x")): 2,
},
},
)
out := BabbageTransactionOutput{
OutputAddress: addr,
OutputAmount: mary.MaryTransactionOutputValue{Amount: 456, Assets: &ma},
OutputAmount: mary.MaryTransactionOutputValue{
Amount: 456,
Assets: &ma,
},
}
s := out.String()
expected := "(BabbageTransactionOutput address=" + addrStr + " amount=456 assets=" + ma.String() + ")"
Expand Down
5 changes: 4 additions & 1 deletion ledger/babbage/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,10 @@ func TestBabbageTransactionBody_Utxorpc(t *testing.T) {

got, err := body.Utxorpc()
if err != nil {
t.Fatalf("Could not convert transaction body to utxorpc format: %v", err)
t.Fatalf(
"Could not convert transaction body to utxorpc format: %v",
err,
)
}
if got.Fee != 100 {
t.Errorf("Fee mismatch: got %d, want 100", got.Fee)
Expand Down
10 changes: 8 additions & 2 deletions ledger/common/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,21 @@ func (a *Address) populateFromBytes(data []byte) error {
// Payment payload
payload := data[1:]
switch a.addressType {
case AddressTypeKeyKey, AddressTypeKeyScript, AddressTypeKeyPointer, AddressTypeKeyNone:
case AddressTypeKeyKey,
AddressTypeKeyScript,
AddressTypeKeyPointer,
AddressTypeKeyNone:
if len(payload) < AddressHashSize {
return errors.New("invalid payment payload: key hash too small")
}
a.paymentPayload = AddressPayloadKeyHash{
Hash: AddrKeyHash(payload[0:AddressHashSize]),
}
payload = payload[AddressHashSize:]
case AddressTypeScriptKey, AddressTypeScriptScript, AddressTypeScriptPointer, AddressTypeScriptNone:
case AddressTypeScriptKey,
AddressTypeScriptScript,
AddressTypeScriptPointer,
AddressTypeScriptNone:
if len(payload) < AddressHashSize {
return errors.New("invalid payment payload: script hash too small")
}
Expand Down
10 changes: 8 additions & 2 deletions ledger/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,21 @@ func (m *MultiAsset[T]) String() string {
}

policies := slices.Collect(maps.Keys(norm))
slices.SortFunc(policies, func(a, b Blake2b224) int { return bytes.Compare(a.Bytes(), b.Bytes()) })
slices.SortFunc(
policies,
func(a, b Blake2b224) int { return bytes.Compare(a.Bytes(), b.Bytes()) },
)

var b strings.Builder
b.WriteByte('[')
first := true
for _, pid := range policies {
assets := norm[pid]
names := slices.Collect(maps.Keys(assets))
slices.SortFunc(names, func(a, b cbor.ByteString) int { return bytes.Compare(a.Bytes(), b.Bytes()) })
slices.SortFunc(
names,
func(a, b cbor.ByteString) int { return bytes.Compare(a.Bytes(), b.Bytes()) },
)

for _, name := range names {
if !first {
Expand Down
11 changes: 9 additions & 2 deletions ledger/common/script/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,11 @@ func votingInfo(
) KeyValuePairs[*lcommon.Voter, KeyValuePairs[*lcommon.GovActionId, lcommon.VotingProcedure]] {
var ret KeyValuePairs[*lcommon.Voter, KeyValuePairs[*lcommon.GovActionId, lcommon.VotingProcedure]]
for voter, voterData := range votingProcedures {
voterPairs := make(KeyValuePairs[*lcommon.GovActionId, lcommon.VotingProcedure], 0, len(votingProcedures))
voterPairs := make(
KeyValuePairs[*lcommon.GovActionId, lcommon.VotingProcedure],
0,
len(votingProcedures),
)
for govActionId, votingProcedure := range voterData {
voterPairs = append(
voterPairs,
Expand All @@ -473,7 +477,10 @@ func votingInfo(
voterPairs,
func(a, b KeyValuePair[*lcommon.GovActionId, lcommon.VotingProcedure]) int {
// Compare TX ID
x := bytes.Compare(a.Key.TransactionId[:], b.Key.TransactionId[:])
x := bytes.Compare(
a.Key.TransactionId[:],
b.Key.TransactionId[:],
)
if x != 0 {
return x
}
Expand Down
19 changes: 16 additions & 3 deletions ledger/conway/conway_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,11 @@ func TestConwayTx_CborRoundTrip_UsingCborEncode(t *testing.T) {
}

if !bytes.Equal(orig, enc) {
t.Errorf("CBOR round-trip mismatch\noriginal: %x\nencoded : %x", orig, enc)
t.Errorf(
"CBOR round-trip mismatch\noriginal: %x\nencoded : %x",
orig,
enc,
)

i := -1
for j := 0; j < len(orig) && j < len(enc); j++ {
Expand All @@ -155,7 +159,12 @@ func TestConwayTx_CborRoundTrip_UsingCborEncode(t *testing.T) {
}
}
if i != -1 {
t.Logf("first diff at byte %d: orig=0x%02x enc=0x%02x", i, orig[i], enc[i])
t.Logf(
"first diff at byte %d: orig=0x%02x enc=0x%02x",
i,
orig[i],
enc[i],
)
} else {
t.Logf("length mismatch: orig=%d enc=%d", len(orig), len(enc))
}
Expand All @@ -181,7 +190,11 @@ func TestConwayTx_Utxorpc(t *testing.T) {

expHash := tx.Id().Bytes()
if !bytes.Equal(utxoTx.Hash, expHash) {
t.Errorf("tx hash mismatch\nexpected: %x\nactual : %x", expHash, utxoTx.Hash)
t.Errorf(
"tx hash mismatch\nexpected: %x\nactual : %x",
expHash,
utxoTx.Hash,
)
}

if got, want := len(utxoTx.Inputs), len(tx.Inputs()); got != want {
Expand Down
60 changes: 50 additions & 10 deletions ledger/conway/pparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,23 @@ func (u ConwayProtocolParameterUpdate) ToPlutusData() data.PlutusData {
push(1, data.NewInteger(new(big.Int).SetUint64(uint64(*u.MinFeeB))))
}
if u.MaxBlockBodySize != nil {
push(2, data.NewInteger(new(big.Int).SetUint64(uint64(*u.MaxBlockBodySize))))
push(
2,
data.NewInteger(
new(big.Int).SetUint64(uint64(*u.MaxBlockBodySize)),
),
)
}
if u.MaxTxSize != nil {
push(3, data.NewInteger(new(big.Int).SetUint64(uint64(*u.MaxTxSize))))
}
if u.MaxBlockHeaderSize != nil {
push(4, data.NewInteger(new(big.Int).SetUint64(uint64(*u.MaxBlockHeaderSize))))
push(
4,
data.NewInteger(
new(big.Int).SetUint64(uint64(*u.MaxBlockHeaderSize)),
),
)
}
if u.KeyDeposit != nil {
push(5, data.NewInteger(new(big.Int).SetUint64(uint64(*u.KeyDeposit))))
Expand Down Expand Up @@ -452,10 +462,16 @@ func (u ConwayProtocolParameterUpdate) ToPlutusData() data.PlutusData {
)
}
if u.MinPoolCost != nil {
push(16, data.NewInteger(new(big.Int).SetUint64(uint64(*u.MinPoolCost))))
push(
16,
data.NewInteger(new(big.Int).SetUint64(uint64(*u.MinPoolCost))),
)
}
if u.AdaPerUtxoByte != nil {
push(17, data.NewInteger(new(big.Int).SetUint64(uint64(*u.AdaPerUtxoByte))))
push(
17,
data.NewInteger(new(big.Int).SetUint64(uint64(*u.AdaPerUtxoByte))),
)
}
// TODO: CostModels
if u.ExecutionCosts != nil {
Expand Down Expand Up @@ -489,13 +505,26 @@ func (u ConwayProtocolParameterUpdate) ToPlutusData() data.PlutusData {
)
}
if u.MaxValueSize != nil {
push(22, data.NewInteger(new(big.Int).SetUint64(uint64(*u.MaxValueSize))))
push(
22,
data.NewInteger(new(big.Int).SetUint64(uint64(*u.MaxValueSize))),
)
}
if u.CollateralPercentage != nil {
push(23, data.NewInteger(new(big.Int).SetUint64(uint64(*u.CollateralPercentage))))
push(
23,
data.NewInteger(
new(big.Int).SetUint64(uint64(*u.CollateralPercentage)),
),
)
}
if u.MaxCollateralInputs != nil {
push(24, data.NewInteger(new(big.Int).SetUint64(uint64(*u.MaxCollateralInputs))))
push(
24,
data.NewInteger(
new(big.Int).SetUint64(uint64(*u.MaxCollateralInputs)),
),
)
}
if u.PoolVotingThresholds != nil {
push(25, u.PoolVotingThresholds.ToPlutusData())
Expand All @@ -504,13 +533,21 @@ func (u ConwayProtocolParameterUpdate) ToPlutusData() data.PlutusData {
push(26, u.DRepVotingThresholds.ToPlutusData())
}
if u.MinCommitteeSize != nil {
push(27, data.NewInteger(new(big.Int).SetUint64(uint64(*u.MinCommitteeSize))))
push(
27,
data.NewInteger(
new(big.Int).SetUint64(uint64(*u.MinCommitteeSize)),
),
)
}
if u.CommitteeTermLimit != nil {
push(28, data.NewInteger(new(big.Int).SetUint64(*u.CommitteeTermLimit)))
}
if u.GovActionValidityPeriod != nil {
push(29, data.NewInteger(new(big.Int).SetUint64(*u.GovActionValidityPeriod)))
push(
29,
data.NewInteger(new(big.Int).SetUint64(*u.GovActionValidityPeriod)),
)
}
if u.GovActionDeposit != nil {
push(30, data.NewInteger(new(big.Int).SetUint64(*u.GovActionDeposit)))
Expand All @@ -519,7 +556,10 @@ func (u ConwayProtocolParameterUpdate) ToPlutusData() data.PlutusData {
push(31, data.NewInteger(new(big.Int).SetUint64(*u.DRepDeposit)))
}
if u.DRepInactivityPeriod != nil {
push(32, data.NewInteger(new(big.Int).SetUint64(*u.DRepInactivityPeriod)))
push(
32,
data.NewInteger(new(big.Int).SetUint64(*u.DRepInactivityPeriod)),
)
}
if u.MinFeeRefScriptCostPerByte != nil {
push(33,
Expand Down
5 changes: 4 additions & 1 deletion ledger/conway/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,10 @@ func TestConwayTransactionBody_Utxorpc(t *testing.T) {

got, err := body.Utxorpc()
if err != nil {
t.Fatalf("Could not convert the transaction body to utxorpc format %v", err)
t.Fatalf(
"Could not convert the transaction body to utxorpc format %v",
err,
)
}

if got.Fee != 1000 {
Expand Down
19 changes: 15 additions & 4 deletions ledger/mary/mary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,21 @@ func TestMaryTransactionOutputString(t *testing.T) {
addr, _ := common.NewAddress(addrStr)
ma := common.NewMultiAsset[common.MultiAssetTypeOutput](
map[common.Blake2b224]map[cbor.ByteString]uint64{
common.NewBlake2b224(make([]byte, 28)): {cbor.NewByteString([]byte("token")): 2},
common.NewBlake2b224(make([]byte, 28)): {
cbor.NewByteString([]byte("token")): 2,
},
},
)
out := MaryTransactionOutput{
OutputAddress: addr,
OutputAmount: MaryTransactionOutputValue{Amount: 456, Assets: &ma},
}
s := out.String()
expected := fmt.Sprintf("(MaryTransactionOutput address=%s amount=456 assets=%s)", addrStr, ma.String())
expected := fmt.Sprintf(
"(MaryTransactionOutput address=%s amount=456 assets=%s)",
addrStr,
ma.String(),
)
if s != expected {
t.Fatalf("unexpected string: %s", s)
}
Expand All @@ -143,8 +149,13 @@ func TestMaryOutputTooBigErrorFormatting(t *testing.T) {
OutputAddress: addr,
OutputAmount: MaryTransactionOutputValue{Amount: 456},
}
errStr := OutputTooBigUtxoError{Outputs: []common.TransactionOutput{out}}.Error()
expected := fmt.Sprintf("output value too large: (MaryTransactionOutput address=%s amount=456)", addrStr)
errStr := OutputTooBigUtxoError{
Outputs: []common.TransactionOutput{out},
}.Error()
expected := fmt.Sprintf(
"output value too large: (MaryTransactionOutput address=%s amount=456)",
addrStr,
)
if errStr != expected {
t.Fatalf("unexpected error: %s", errStr)
}
Expand Down
5 changes: 4 additions & 1 deletion ledger/mary/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ func TestMaryTransactionBody_Utxorpc(t *testing.T) {

got, err := body.Utxorpc()
if err != nil {
t.Fatalf("Could not convert the transaction body to utxorpc format %v", err)
t.Fatalf(
"Could not convert the transaction body to utxorpc format %v",
err,
)
}

if got.Fee != 100 {
Expand Down
5 changes: 4 additions & 1 deletion ledger/shelley/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ func TestShelleyTransactionBody_Utxorpc(t *testing.T) {
// Convert the transaction body to utxorpc format
actual, err := txBody.Utxorpc()
if err != nil {
t.Fatalf("Could not convert the transaction body to utxorpc format %v", err)
t.Fatalf(
"Could not convert the transaction body to utxorpc format %v",
err,
)
}

// Check that the fee matches
Expand Down
Loading