diff --git a/ledger/allegra/block_test.go b/ledger/allegra/block_test.go index 911b7d6b..f6762c77 100644 --- a/ledger/allegra/block_test.go +++ b/ledger/allegra/block_test.go @@ -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") @@ -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", + ) } }) } diff --git a/ledger/alonzo/alonzo.go b/ledger/alonzo/alonzo.go index a2c0eb4e..a29009d8 100644 --- a/ledger/alonzo/alonzo.go +++ b/ledger/alonzo/alonzo.go @@ -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), + ), }, }, ), diff --git a/ledger/alonzo/alonzo_test.go b/ledger/alonzo/alonzo_test.go index 12e276e5..ef4e04f7 100644 --- a/ledger/alonzo/alonzo_test.go +++ b/ledger/alonzo/alonzo_test.go @@ -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, + ) } } @@ -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)), }, }, @@ -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, + ) } } @@ -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++ } diff --git a/ledger/alonzo/block_test.go b/ledger/alonzo/block_test.go index e2316701..b89c40d0 100644 --- a/ledger/alonzo/block_test.go +++ b/ledger/alonzo/block_test.go @@ -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() @@ -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", + ) }) } diff --git a/ledger/babbage/babbage.go b/ledger/babbage/babbage.go index 10286bf0..802a985b 100644 --- a/ledger/babbage/babbage.go +++ b/ledger/babbage/babbage.go @@ -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), + ), }, }, ), diff --git a/ledger/babbage/babbage_test.go b/ledger/babbage/babbage_test.go index 0a6cb62d..74a99433 100644 --- a/ledger/babbage/babbage_test.go +++ b/ledger/babbage/babbage_test.go @@ -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, + ) } } @@ -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)), }, }, @@ -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, + ) } } diff --git a/ledger/babbage/block_test.go b/ledger/babbage/block_test.go index b6b972a6..d99a5b56 100644 --- a/ledger/babbage/block_test.go +++ b/ledger/babbage/block_test.go @@ -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 @@ -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), + ) } } } diff --git a/ledger/byron/block_test.go b/ledger/byron/block_test.go index 6de3fb91..c6468961 100644 --- a/ledger/byron/block_test.go +++ b/ledger/byron/block_test.go @@ -24,7 +24,12 @@ func TestByronTransactionUtxorpc(t *testing.T) { assert.NotNil(t, block) txs := block.Transactions() - assert.Greater(t, len(txs), 0, "Expected at least one transaction in the block") + assert.Greater( + t, + len(txs), + 0, + "Expected at least one transaction in the block", + ) for _, tx := range txs { byronTx, ok := tx.(*byron.ByronTransaction) @@ -35,20 +40,43 @@ func TestByronTransactionUtxorpc(t *testing.T) { assert.NotNil(t, utxoTx, "Utxorpc() should not return nil") txHash := byronTx.Hash() - assert.NotEmpty(t, txHash.String(), "Transaction hash should not be empty") + assert.NotEmpty( + t, + txHash.String(), + "Transaction hash should not be empty", + ) inputs := byronTx.Inputs() - assert.Equal(t, len(inputs), len(byronTx.Consumed()), "Consumed inputs should match Inputs() length") + assert.Equal( + t, + len(inputs), + len(byronTx.Consumed()), + "Consumed inputs should match Inputs() length", + ) produced := byronTx.Produced() - assert.Equal(t, len(produced), len(byronTx.Outputs()), "Produced should match Outputs() length") + assert.Equal( + t, + len(produced), + len(byronTx.Outputs()), + "Produced should match Outputs() length", + ) for _, utxo := range produced { rpcOut, err := utxo.Output.Utxorpc() assert.NoError(t, err) assert.NotNil(t, rpcOut, "Utxorpc output should not be nil") - assert.Greater(t, rpcOut.Coin, uint64(0), "Coin amount should be greater than 0") - assert.NotEmpty(t, rpcOut.Address, "Address bytes should not be empty") + assert.Greater( + t, + rpcOut.Coin, + uint64(0), + "Coin amount should be greater than 0", + ) + assert.NotEmpty( + t, + rpcOut.Address, + "Address bytes should not be empty", + ) } } } diff --git a/ledger/common/address.go b/ledger/common/address.go index a7dc901b..3154e03f 100644 --- a/ledger/common/address.go +++ b/ledger/common/address.go @@ -109,17 +109,23 @@ func NewAddressFromParts( stakingAddr []byte, ) (Address, error) { // Validate network ID - if networkId != AddressNetworkTestnet && networkId != AddressNetworkMainnet { + if networkId != AddressNetworkTestnet && + networkId != AddressNetworkMainnet { return Address{}, errors.New("invalid network ID") } // Handle stake-only addresses if addrType == AddressTypeNoneKey || addrType == AddressTypeNoneScript { if len(paymentAddr) > 0 { - return Address{}, errors.New("payment address must be empty for stake-only addresses") + return Address{}, errors.New( + "payment address must be empty for stake-only addresses", + ) } if len(stakingAddr) != AddressHashSize { - return Address{}, fmt.Errorf("staking key must be exactly %d bytes", AddressHashSize) + return Address{}, fmt.Errorf( + "staking key must be exactly %d bytes", + AddressHashSize, + ) } return Address{ addressType: addrType, @@ -130,11 +136,17 @@ func NewAddressFromParts( // Handle regular addresses if len(paymentAddr) != AddressHashSize { - return Address{}, fmt.Errorf("payment address must be exactly %d bytes", AddressHashSize) + return Address{}, fmt.Errorf( + "payment address must be exactly %d bytes", + AddressHashSize, + ) } if len(stakingAddr) > 0 && len(stakingAddr) != AddressHashSize { - return Address{}, fmt.Errorf("staking address must be empty or exactly %d bytes", AddressHashSize) + return Address{}, fmt.Errorf( + "staking address must be empty or exactly %d bytes", + AddressHashSize, + ) } return Address{ @@ -311,12 +323,18 @@ func (a *Address) ToPlutusData() data.PlutusData { // Build payment part var paymentPd data.PlutusData switch a.addressType { - case AddressTypeKeyKey, AddressTypeKeyScript, AddressTypeKeyPointer, AddressTypeKeyNone: + case AddressTypeKeyKey, + AddressTypeKeyScript, + AddressTypeKeyPointer, + AddressTypeKeyNone: paymentPd = data.NewConstr( 0, data.NewByteString(a.paymentAddress), ) - case AddressTypeScriptKey, AddressTypeScriptScript, AddressTypeScriptPointer, AddressTypeScriptNone: + case AddressTypeScriptKey, + AddressTypeScriptScript, + AddressTypeScriptPointer, + AddressTypeScriptNone: paymentPd = data.NewConstr( 1, data.NewByteString(a.paymentAddress), diff --git a/ledger/common/address_test.go b/ledger/common/address_test.go index 9eb7c708..90e684ba 100644 --- a/ledger/common/address_test.go +++ b/ledger/common/address_test.go @@ -370,7 +370,11 @@ func TestAddressToPlutusData(t *testing.T) { } tmpPd := tmpAddr.ToPlutusData() if !reflect.DeepEqual(tmpPd, testDef.expectedData) { - t.Errorf("did not get expected PlutusData\n got: %#v\n wanted: %#v", tmpPd, testDef.expectedData) + t.Errorf( + "did not get expected PlutusData\n got: %#v\n wanted: %#v", + tmpPd, + testDef.expectedData, + ) } } } diff --git a/ledger/common/certs.go b/ledger/common/certs.go index fb4d5f23..aa257ab2 100644 --- a/ledger/common/certs.go +++ b/ledger/common/certs.go @@ -375,8 +375,8 @@ func (p *PoolRelay) Utxorpc() (*utxorpc.Relay, error) { } type PoolRegistrationCertificate struct { - cbor.StructAsArray `json:"-"` - cbor.DecodeStoreCbor `json:"-"` + cbor.StructAsArray ` json:"-"` + cbor.DecodeStoreCbor ` json:"-"` CertType uint `json:"certType,omitempty"` Operator PoolKeyHash `json:"operator"` VrfKeyHash VrfKeyHash `json:"vrfKeyHash"` @@ -449,10 +449,17 @@ func (p *PoolRegistrationCertificate) UnmarshalJSON(data []byte) error { if ra.Credential.KeyHash != "" { hashBytes, err := hex.DecodeString(ra.Credential.KeyHash) if err != nil { - return fmt.Errorf("failed to decode reward account key hash: %w", err) + return fmt.Errorf( + "failed to decode reward account key hash: %w", + err, + ) } if len(hashBytes) != AddressHashSize { - return fmt.Errorf("invalid key hash length: expected %d, got %d", AddressHashSize, len(hashBytes)) + return fmt.Errorf( + "invalid key hash length: expected %d, got %d", + AddressHashSize, + len(hashBytes), + ) } p.RewardAccount = AddrKeyHash(NewBlake2b224(hashBytes)) } diff --git a/ledger/common/common.go b/ledger/common/common.go index 1a26d39c..0c781c10 100644 --- a/ledger/common/common.go +++ b/ledger/common/common.go @@ -207,13 +207,19 @@ func (m *MultiAsset[T]) ToPlutusData() data.PlutusData { tmpData := make([][2]data.PlutusData, 0, len(m.data)) // Sort policy IDs policyKeys := slices.Collect(maps.Keys(m.data)) - slices.SortFunc(policyKeys, func(a, b Blake2b224) int { return bytes.Compare(a.Bytes(), b.Bytes()) }) + slices.SortFunc( + policyKeys, + func(a, b Blake2b224) int { return bytes.Compare(a.Bytes(), b.Bytes()) }, + ) for _, policyId := range policyKeys { policyData := m.data[policyId] tmpPolicyData := make([][2]data.PlutusData, 0, len(policyData)) // Sort asset names assetKeys := slices.Collect(maps.Keys(policyData)) - slices.SortFunc(assetKeys, func(a, b cbor.ByteString) int { return bytes.Compare(a.Bytes(), b.Bytes()) }) + slices.SortFunc( + assetKeys, + func(a, b cbor.ByteString) int { return bytes.Compare(a.Bytes(), b.Bytes()) }, + ) for _, assetName := range assetKeys { amount := policyData[assetName] tmpPolicyData = append( diff --git a/ledger/common/common_test.go b/ledger/common/common_test.go index b550e175..7d6bdda1 100644 --- a/ledger/common/common_test.go +++ b/ledger/common/common_test.go @@ -145,11 +145,19 @@ func TestMultiAssetToPlutusData(t *testing.T) { expectedData: data.NewMap( [][2]data.PlutusData{ { - 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)), }, }, @@ -172,22 +180,38 @@ func TestMultiAssetToPlutusData(t *testing.T) { expectedData: data.NewMap( [][2]data.PlutusData{ { - 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)), }, }, @@ -208,7 +232,11 @@ func TestMultiAssetToPlutusData(t *testing.T) { t.Fatalf("test def multi-asset object was not expected type: %T", v) } if !reflect.DeepEqual(tmpData, testDef.expectedData) { - t.Fatalf("did not get expected PlutusData\n got: %#v\n wanted: %#v", tmpData, testDef.expectedData) + t.Fatalf( + "did not get expected PlutusData\n got: %#v\n wanted: %#v", + tmpData, + testDef.expectedData, + ) } } } @@ -334,14 +362,20 @@ func TestBlake2b224_String(t *testing.T) { func TestBlake2b224_ToPlutusData(t *testing.T) { testData := []byte("blinklabs") hash := Blake2b224Hash(testData) - expectedHash, err := hex.DecodeString("d33ef286551f50d455cfeb68b45b02622fb05ef21cfd1aabd0d7880c") + expectedHash, err := hex.DecodeString( + "d33ef286551f50d455cfeb68b45b02622fb05ef21cfd1aabd0d7880c", + ) if err != nil { t.Fatalf("unexpected error: %s", err) } expectedPd := data.NewByteString(expectedHash) tmpPd := hash.ToPlutusData() if !reflect.DeepEqual(tmpPd, expectedPd) { - t.Fatalf("did not get expected PlutusData: got: %#v\n wanted: %#v", tmpPd, expectedPd) + t.Fatalf( + "did not get expected PlutusData: got: %#v\n wanted: %#v", + tmpPd, + expectedPd, + ) } } diff --git a/ledger/common/genesis_test.go b/ledger/common/genesis_test.go index 260cae24..8901c7b7 100644 --- a/ledger/common/genesis_test.go +++ b/ledger/common/genesis_test.go @@ -32,7 +32,11 @@ func TestGenesisRatNumDenom(t *testing.T) { t.Fatalf("unexpected error: %s", err) } if testData.TestRat.Cmp(expectedRat) != 0 { - t.Errorf("did not get expected value: got %s, wanted %s", testData.TestRat.String(), expectedRat.String()) + t.Errorf( + "did not get expected value: got %s, wanted %s", + testData.TestRat.String(), + expectedRat.String(), + ) } } @@ -46,6 +50,10 @@ func TestGenesisRatFloat(t *testing.T) { t.Fatalf("unexpected error: %s", err) } if testData.TestRat.Cmp(expectedRat) != 0 { - t.Errorf("did not get expected value: got %s, wanted %s", testData.TestRat.String(), expectedRat.String()) + t.Errorf( + "did not get expected value: got %s, wanted %s", + testData.TestRat.String(), + expectedRat.String(), + ) } } diff --git a/ledger/common/gov.go b/ledger/common/gov.go index ba810234..c020ddfc 100644 --- a/ledger/common/gov.go +++ b/ledger/common/gov.go @@ -240,9 +240,14 @@ type HardForkInitiationGovAction struct { func (a *HardForkInitiationGovAction) ToPlutusData() data.PlutusData { return data.NewConstr(1, a.ActionId.ToPlutusData(), - data.NewConstr(0, - data.NewInteger(new(big.Int).SetUint64(uint64(a.ProtocolVersion.Major))), - data.NewInteger(new(big.Int).SetUint64(uint64(a.ProtocolVersion.Minor))), + data.NewConstr( + 0, + data.NewInteger( + new(big.Int).SetUint64(uint64(a.ProtocolVersion.Major)), + ), + data.NewInteger( + new(big.Int).SetUint64(uint64(a.ProtocolVersion.Minor)), + ), ), ) } diff --git a/ledger/common/gov_test.go b/ledger/common/gov_test.go index 68bc52f5..6d79981f 100644 --- a/ledger/common/gov_test.go +++ b/ledger/common/gov_test.go @@ -26,8 +26,66 @@ import ( // Ttests the ToPlutusData method for Voter types func TestVoterToPlutusData(t *testing.T) { // Use the same hash value for all tests to avoid confusion - testHash := [28]byte{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11} - testHashBytes := []byte{0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11} + testHash := [28]byte{ + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + } + testHashBytes := []byte{ + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + 0x11, + } testCases := []struct { name string @@ -40,7 +98,10 @@ func TestVoterToPlutusData(t *testing.T) { Type: VoterTypeConstitutionalCommitteeHotScriptHash, Hash: testHash, }, - expectedData: data.NewConstr(0, data.NewConstr(1, data.NewByteString(testHashBytes))), + expectedData: data.NewConstr( + 0, + data.NewConstr(1, data.NewByteString(testHashBytes)), + ), }, { name: "ConstitutionalCommitteeHotKeyHash", @@ -48,7 +109,10 @@ func TestVoterToPlutusData(t *testing.T) { Type: VoterTypeConstitutionalCommitteeHotKeyHash, Hash: testHash, }, - expectedData: data.NewConstr(0, data.NewConstr(0, data.NewByteString(testHashBytes))), + expectedData: data.NewConstr( + 0, + data.NewConstr(0, data.NewByteString(testHashBytes)), + ), }, { name: "DRepScriptHash", @@ -56,7 +120,10 @@ func TestVoterToPlutusData(t *testing.T) { Type: VoterTypeDRepScriptHash, Hash: testHash, }, - expectedData: data.NewConstr(1, data.NewConstr(1, data.NewByteString(testHashBytes))), + expectedData: data.NewConstr( + 1, + data.NewConstr(1, data.NewByteString(testHashBytes)), + ), }, { name: "DRepKeyHash", @@ -64,7 +131,10 @@ func TestVoterToPlutusData(t *testing.T) { Type: VoterTypeDRepKeyHash, Hash: testHash, }, - expectedData: data.NewConstr(1, data.NewConstr(0, data.NewByteString(testHashBytes))), + expectedData: data.NewConstr( + 1, + data.NewConstr(0, data.NewByteString(testHashBytes)), + ), }, { name: "StakingPoolKeyHash", @@ -88,7 +158,11 @@ func TestVoterToPlutusData(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.voter.ToPlutusData() if !reflect.DeepEqual(result, tc.expectedData) { - t.Errorf("ToPlutusData() = %#v, want %#v", result, tc.expectedData) + t.Errorf( + "ToPlutusData() = %#v, want %#v", + result, + tc.expectedData, + ) } }) } @@ -127,7 +201,11 @@ func TestVoteToPlutusData(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.vote.ToPlutusData() if !reflect.DeepEqual(result, tc.expectedData) { - t.Errorf("ToPlutusData() = %#v, want %#v", result, tc.expectedData) + t.Errorf( + "ToPlutusData() = %#v, want %#v", + result, + tc.expectedData, + ) } }) } @@ -174,7 +252,11 @@ func TestVotingProcedureToPlutusData(t *testing.T) { t.Run(tc.name, func(t *testing.T) { result := tc.procedure.ToPlutusData() if !reflect.DeepEqual(result, tc.expectedData) { - t.Errorf("ToPlutusData() = %#v, want %#v", result, tc.expectedData) + t.Errorf( + "ToPlutusData() = %#v, want %#v", + result, + tc.expectedData, + ) } }) } diff --git a/ledger/conway/block_test.go b/ledger/conway/block_test.go index df856563..0dc9bfe2 100644 --- a/ledger/conway/block_test.go +++ b/ledger/conway/block_test.go @@ -111,15 +111,27 @@ func TestConwayBlockUtxorpc(t *testing.T) { expectedHash := block.Hash().Bytes() if !compareByteSlices(utxoBlock.Header.Hash, expectedHash) { - t.Errorf("block hash mismatch:\nexpected: %x\nactual: %x", expectedHash, utxoBlock.Header.Hash) + t.Errorf( + "block hash mismatch:\nexpected: %x\nactual: %x", + expectedHash, + utxoBlock.Header.Hash, + ) } if utxoBlock.Header.Height != block.BlockNumber() { - t.Errorf("block height mismatch: expected %d, got %d", block.BlockNumber(), utxoBlock.Header.Height) + t.Errorf( + "block height mismatch: expected %d, got %d", + block.BlockNumber(), + utxoBlock.Header.Height, + ) } if utxoBlock.Header.Slot != block.SlotNumber() { - t.Errorf("block slot mismatch: expected %d, got %d", block.SlotNumber(), utxoBlock.Header.Slot) + t.Errorf( + "block slot mismatch: expected %d, got %d", + block.SlotNumber(), + utxoBlock.Header.Slot, + ) } if utxoBlock.Body == nil { @@ -128,7 +140,11 @@ func TestConwayBlockUtxorpc(t *testing.T) { expectedTxCount := len(block.TransactionBodies) if len(utxoBlock.Body.Tx) != expectedTxCount { - t.Errorf("transaction count mismatch: expected %d, got %d", expectedTxCount, len(utxoBlock.Body.Tx)) + t.Errorf( + "transaction count mismatch: expected %d, got %d", + expectedTxCount, + len(utxoBlock.Body.Tx), + ) } if expectedTxCount > 0 { @@ -137,15 +153,27 @@ func TestConwayBlockUtxorpc(t *testing.T) { expectedTxHash := firstTx.Hash().Bytes() if !compareByteSlices(utxoFirstTx.Hash, expectedTxHash) { - t.Errorf("first tx hash mismatch:\nexpected: %x\nactual: %x", expectedTxHash, utxoFirstTx.Hash) + t.Errorf( + "first tx hash mismatch:\nexpected: %x\nactual: %x", + expectedTxHash, + utxoFirstTx.Hash, + ) } if len(utxoFirstTx.Inputs) != len(firstTx.Inputs()) { - t.Errorf("first tx input count mismatch: expected %d, got %d", len(firstTx.Inputs()), len(utxoFirstTx.Inputs)) + t.Errorf( + "first tx input count mismatch: expected %d, got %d", + len(firstTx.Inputs()), + len(utxoFirstTx.Inputs), + ) } if len(utxoFirstTx.Outputs) != len(firstTx.Outputs()) { - t.Errorf("first tx output count mismatch: expected %d, got %d", len(firstTx.Outputs()), len(utxoFirstTx.Outputs)) + t.Errorf( + "first tx output count mismatch: expected %d, got %d", + len(firstTx.Outputs()), + len(utxoFirstTx.Outputs), + ) } } } diff --git a/ledger/conway/conway_test.go b/ledger/conway/conway_test.go index 8a287f02..eb9aa6ae 100644 --- a/ledger/conway/conway_test.go +++ b/ledger/conway/conway_test.go @@ -98,10 +98,18 @@ func TestConwayRedeemersIter(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++ } diff --git a/ledger/shelley/block_test.go b/ledger/shelley/block_test.go index 353d8d52..08a5e4c0 100644 --- a/ledger/shelley/block_test.go +++ b/ledger/shelley/block_test.go @@ -117,13 +117,25 @@ func TestShelleyBlockUtxorpc(t *testing.T) { expectedTxCount := len(block.TransactionBodies) if len(utxoBlock.Body.Tx) != expectedTxCount { - t.Errorf("expected %d transactions, got %d", expectedTxCount, len(utxoBlock.Body.Tx)) + t.Errorf( + "expected %d transactions, got %d", + expectedTxCount, + len(utxoBlock.Body.Tx), + ) } if utxoBlock.Header.Height != block.BlockNumber() { - t.Errorf("height mismatch: expected %d, got %d", block.BlockNumber(), utxoBlock.Header.Height) + t.Errorf( + "height mismatch: expected %d, got %d", + block.BlockNumber(), + utxoBlock.Header.Height, + ) } if utxoBlock.Header.Slot != block.SlotNumber() { - t.Errorf("slot mismatch: expected %d, got %d", block.SlotNumber(), utxoBlock.Header.Slot) + t.Errorf( + "slot mismatch: expected %d, got %d", + block.SlotNumber(), + utxoBlock.Header.Slot, + ) } } diff --git a/ledger/shelley/genesis.go b/ledger/shelley/genesis.go index dd3bb644..1ca741df 100644 --- a/ledger/shelley/genesis.go +++ b/ledger/shelley/genesis.go @@ -109,7 +109,9 @@ func (g ShelleyGenesis) MarshalCBOR() ([]byte, error) { if err != nil { return nil, err } - cborStake[cbor.NewByteString(stakeAddrBytes)] = cbor.NewByteString(poolIdBytes) + cborStake[cbor.NewByteString(stakeAddrBytes)] = cbor.NewByteString( + poolIdBytes, + ) } slotLengthMs := &big.Rat{} @@ -299,7 +301,9 @@ func (g *ShelleyGenesis) InitialPools() (map[string]common.PoolRegistrationCerti return pools, poolStake, nil } -func (g *ShelleyGenesis) PoolById(poolId string) (*common.PoolRegistrationCertificate, []common.Address, error) { +func (g *ShelleyGenesis) PoolById( + poolId string, +) (*common.PoolRegistrationCertificate, []common.Address, error) { if len(poolId) != 56 { return nil, nil, errors.New("invalid pool ID length") } diff --git a/ledger/shelley/genesis_test.go b/ledger/shelley/genesis_test.go index 05dfa588..85b99e3c 100644 --- a/ledger/shelley/genesis_test.go +++ b/ledger/shelley/genesis_test.go @@ -292,7 +292,9 @@ func TestGenesisStaking(t *testing.T) { }` t.Run("TestInitialPools", func(t *testing.T) { - genesis, err := shelley.NewShelleyGenesisFromReader(strings.NewReader(testGenesis)) + genesis, err := shelley.NewShelleyGenesisFromReader( + strings.NewReader(testGenesis), + ) if err != nil { t.Fatalf("Genesis parsing failed: %v", err) } @@ -349,7 +351,9 @@ func TestGenesisStaking(t *testing.T) { }) t.Run("TestPoolById", func(t *testing.T) { - genesis, err := shelley.NewShelleyGenesisFromReader(strings.NewReader(testGenesis)) + genesis, err := shelley.NewShelleyGenesisFromReader( + strings.NewReader(testGenesis), + ) if err != nil { t.Fatalf("Genesis parsing failed: %v", err) } diff --git a/ledger/shelley/tx_test.go b/ledger/shelley/tx_test.go index 5ebf345d..5fc2f04d 100644 --- a/ledger/shelley/tx_test.go +++ b/ledger/shelley/tx_test.go @@ -42,6 +42,10 @@ func TestShelleyTransactionInputToPlutusData(t *testing.T) { ) tmpData := testInput.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, + ) } }