Skip to content

Commit

Permalink
fix: golangci-lint workflow and fix errors reported (#42)
Browse files Browse the repository at this point in the history
* fix: golangci-lint workflow and fix errors reported

* fix: simplify bool return in backend cache

* fix: use struct key names in field assignments

* fix: run golangci-lint always

* fix: switch from deprecated io/ioutil

* fix: remove unreachable return

* fix: use string interpolation syntax

* fix: clean up ineffectual assignments

* fix: don't drop errors

* fix: explicit continue for unimplemented branch

* fix: remove unnecessary assignments in loop iterations over maps

---------

Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
  • Loading branch information
wolf31o2 authored Jan 22, 2025
1 parent c020a08 commit ee1da4b
Show file tree
Hide file tree
Showing 23 changed files with 237 additions and 79 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This file was copied from the following URL and modified:
# https://github.com/golangci/golangci-lint-action/blob/master/README.md#how-to-use

name: golangci-lint
on:
push:
tags:
- v*
branches:
- master
pull_request:

permissions:
contents: read
pull-requests: read

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.22.x
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
args: --timeout=10m
# Only show new issues in a PR but show all issues for pushes
# only-new-issues: ${{ github.event_name == 'pull_request' && 'true' || 'false' }}
12 changes: 5 additions & 7 deletions ApolloBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ func (b *Apollo) ConsumeAssetsFromUtxo(utxo UTxO.UTxO, payments ...PaymentI) *Ap
}
if selectedValue.Less(Value.Value{}) {
panic("selected value is negative")
return b
}
b.payments = append(b.payments, payments...)
selectedValue = selectedValue.RemoveZeroAssets()
Expand Down Expand Up @@ -622,7 +621,7 @@ func (b *Apollo) scriptDataHash() (*serialization.ScriptDataHash, error) {
}
// fmt.Println("PRE_HASH", hex.EncodeToString(total_bytes))
// fmt.Println("HASH", hex.EncodeToString(hash))
return &serialization.ScriptDataHash{hash}, nil
return &serialization.ScriptDataHash{Payload: hash}, nil

}

Expand Down Expand Up @@ -829,17 +828,16 @@ func (b *Apollo) getAvailableUtxos() []UTxO.UTxO {
*/
func (b *Apollo) setRedeemerIndexes() *Apollo {
sorted_inputs := SortInputs(b.preselectedUtxos)
done := make([]string, 0)
for i, utxo := range sorted_inputs {
key := hex.EncodeToString(utxo.Input.TransactionId) + fmt.Sprint(utxo.Input.Index)
val, ok := b.redeemersToUTxO[key]
if ok && val.Tag == Redeemer.SPEND {
done = append(done, key)
redeem := b.redeemersToUTxO[key]
redeem.Index = i
b.redeemersToUTxO[key] = redeem
} else if ok && val.Tag == Redeemer.MINT {
//TODO: IMPLEMENT FOR MINTS
// TODO: IMPLEMENT FOR MINTS
continue
}
}
return b
Expand Down Expand Up @@ -1577,7 +1575,7 @@ func (a *Apollo) SetWalletFromMnemonic(
skh, _ := stakeVerKey.Hash()
vkh, _ := verificationKey.Hash()

addr := Address.Address{}
var addr Address.Address
if network == constants.MAINNET {
addr = Address.Address{
StakingPart: skh[:],
Expand Down Expand Up @@ -1619,7 +1617,7 @@ func (a *Apollo) SetWalletFromKeypair(vkey string, skey string, network constant
verificationKey := Key.VerificationKey{Payload: verificationKey_bytes}
vkh, _ := verificationKey.Hash()

addr := Address.Address{}
var addr Address.Address
if network == constants.MAINNET {
addr = Address.Address{
StakingPart: nil,
Expand Down
12 changes: 12 additions & 0 deletions ApolloBuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func TestEnsureTxIsBalanced(t *testing.T) {
t.Error(err)
}
txBytes, err := apollob.GetTx().Bytes()
if err != nil {
t.Error(err)
}
fmt.Println(hex.EncodeToString(txBytes))
inputVal := Value.SimpleValue(0, MultiAsset.MultiAsset[int64]{})
for _, input := range apollob.GetTx().TransactionBody.Inputs {
Expand Down Expand Up @@ -530,6 +533,9 @@ func TestBurnPlutus(t *testing.T) {
t.Error(err)
}
txBytes, err := apollob.GetTx().Bytes()
if err != nil {
t.Error(err)
}
if hex.EncodeToString(
txBytes,
) != "84a5008182584064356431663763323233646338386262343134373461663233623638356530323437333037653934653731356566356536326633323561633934663733303536000181825839010a59337f7b3a913424d7f7a151401e052642b68e948d8cacadc6372016a9999419cc5a61ca62da81e378d7538213a3715a6b858c948c69c91a00e1eefb021a0002f2c509a1581c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3fa14454455354200b58207c2fde0c1908393e41c7b4afbfee2686378e714d70fc335b6cd0142ac6de9772a10581840000f6820000f5f6" {
Expand Down Expand Up @@ -579,6 +585,9 @@ func TestMintPlutus(t *testing.T) {
t.Error(err)
}
txBytes, err := apollob.GetTx().Bytes()
if err != nil {
t.Error(err)
}
if hex.EncodeToString(
txBytes,
) != "84a5008182584064356431663763323233646338386262343134373461663233623638356530323437333037653934653731356566356536326633323561633934663733303536000181825839010a59337f7b3a913424d7f7a151401e052642b68e948d8cacadc6372016a9999419cc5a61ca62da81e378d7538213a3715a6b858c948c69c9821a00e1e193a1581c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3fa1445445535401021a0003002d09a1581c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3fa14454455354010b58207c2fde0c1908393e41c7b4afbfee2686378e714d70fc335b6cd0142ac6de9772a10581840000f6820000f5f6" {
Expand Down Expand Up @@ -635,6 +644,9 @@ func TestMintPlutusWithPayment(t *testing.T) {
t.Error(err)
}
txBytes, err := apollob.GetTx().Bytes()
if err != nil {
t.Error(err)
}
if hex.EncodeToString(
txBytes,
) != "84a5008182584064356431663763323233646338386262343134373461663233623638356530323437333037653934653731356566356536326633323561633934663733303536000182825839010a59337f7b3a913424d7f7a151401e052642b68e948d8cacadc6372016a9999419cc5a61ca62da81e378d7538213a3715a6b858c948c69c9821a001484d0a1581c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3fa1445445535401825839010a59337f7b3a913424d7f7a151401e052642b68e948d8cacadc6372016a9999419cc5a61ca62da81e378d7538213a3715a6b858c948c69c91a00cd466b021a0003168509a1581c279c909f348e533da5808898f87f9a14bb2c3dfbbacccd631d927a3fa14454455354010b58207c2fde0c1908393e41c7b4afbfee2686378e714d70fc335b6cd0142ac6de9772a10581840000f6820000f5f6" {
Expand Down
2 changes: 1 addition & 1 deletion crypto/bech32/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func Decode(bech string) (string, []byte, error) {
moreInfo = fmt.Sprintf("Expected %v, got %v.",
expected, checksum)
}
return "", nil, fmt.Errorf("checksum failed. " + moreInfo)
return "", nil, fmt.Errorf("checksum failed. %s", moreInfo)
}

// We exclude the last 6 bytes, which is the checksum.
Expand Down
2 changes: 1 addition & 1 deletion plutusencoder/customtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func DecodePlutusAddress(data PlutusData.PlutusData, network byte) (Address.Addr
if data.PlutusDataType != PlutusData.PlutusArray && data.TagNr != 121 && len(data.Value.(PlutusData.PlutusIndefArray)) != 2 {
return Address.Address{}, fmt.Errorf("error: Invalid Address Data")
}
isIndef := true
var isIndef bool
switch data.Value.(type) {
case PlutusData.PlutusDefArray:
isIndef = false
Expand Down
14 changes: 13 additions & 1 deletion plutusencoder/plutusencoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ func TestNestedListMarshal(t *testing.T) {
t.Error(err)
}
encoded, err := cbor.Marshal(marshaled)
if err != nil {
t.Error(err)
}
fmt.Println(hex.EncodeToString(encoded))
if hex.EncodeToString(encoded) != "d87a9f44010203041a000f42409fd87b8344010203041a000f42404401020304d87b8344010203041a000f42404401020304ffff" {
t.Error("encoding error")
Expand Down Expand Up @@ -167,6 +170,9 @@ func TestPlutusMarshal(t *testing.T) {
t.Error(err)
}
encoded, err := cbor.Marshal(marshaled)
if err != nil {
t.Error(err)
}
if hex.EncodeToString(encoded) != "d87a9f44010203044b48656c6c6f20576f726c641a000f4240d87b8344010203041a000f42404401020304ff" {
t.Error("encoding error")
}
Expand Down Expand Up @@ -222,6 +228,9 @@ func TestPDAddressesStruct(t *testing.T) {
}
fmt.Println(marshaled)
encoded, err := cbor.Marshal(marshaled)
if err != nil {
t.Error(err)
}
if hex.EncodeToString(encoded) != "d87b81d8799fd8799f581cbb2ff620c0dd8b0adc19e6ffadea1a150c85d1b22d05e2db10c55c61ffd8799fd8799fd8799f581c3b8c8a100c16cf62b9c2bacc40453aaa67ced633993f2b4eec5b88e4ffffffff" {
t.Error(hex.EncodeToString(encoded))
}
Expand Down Expand Up @@ -263,7 +272,10 @@ func TestPDAddress(t *testing.T) {
if err != nil {
t.Error(err)
}
encoded, _ = cbor.Marshal(pd)
encoded, err = cbor.Marshal(pd)
if err != nil {
t.Error(err)
}
if hex.EncodeToString(encoded) != "d8799fd87a9f581c4ab17afc9a19a4f06b6fe229f9501e727d3968bff03acb1a8f86acf5ffd8799fd8799fd8799f581cb60abac5d101517cd99ae6c6c9ab582bc8603a07b57941df212782c5ffffffff" {
t.Error(hex.EncodeToString(encoded))
}
Expand Down
5 changes: 4 additions & 1 deletion serialization/Address/Address_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,10 @@ func TestUnmarshalCbor(t *testing.T) {
cbor := "5839019493315cd92eb5d8c4304e67b7e16ae36d61d34502694657811a2c8e337b62cfff6403a06a3acbc34f8c46003c69fe79a3628cefa9c47251"
decoded, _ := hex.DecodeString(cbor)
addr := Address.Address{}
addr.UnmarshalCBOR(decoded)
err := addr.UnmarshalCBOR(decoded)
if err != nil {
t.Error("Failed unmarshaling", err)
}
if addr.String() != "addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x" {
t.Errorf("\nexpected: %v\nresult: %v", "addr1qx2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3n0d3vllmyqwsx5wktcd8cc3sq835lu7drv2xwl2wywfgse35a3x", addr.String())
}
Expand Down
10 changes: 8 additions & 2 deletions serialization/Amount/Amount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ func TestNoAssetPreAlonzoMarshaling(t *testing.T) {
}

var unmarshaled Amount.Amount
cbor.Unmarshal(marshaled, &unmarshaled)
err := cbor.Unmarshal(marshaled, &unmarshaled)
if err != nil {
t.Error("Failed unmarshaling", err)
}
if !val0.Equal(unmarshaled) {
t.Errorf("Unmarshaling failed. Expected: %v, Got: %v", val0, unmarshaled)
}
Expand All @@ -82,7 +85,10 @@ func TestPreAlonzoMarshalingWAssets(t *testing.T) {
t.Errorf("Marshaling failed. Expected: 821864a1581cfc11a9ef431f81b837736be5f53e4da29b9469c983d07f321262ce61a144746573741864, Got: %x", marshaled)
}
var unmarshaled Amount.Amount
cbor.Unmarshal(marshaled, &unmarshaled)
err := cbor.Unmarshal(marshaled, &unmarshaled)
if err != nil {
t.Error("Failed unmarshaling", err)
}
if !val0.Equal(unmarshaled) {
t.Errorf("Unmarshaling failed. Expected: %v, Got: %v", val0, unmarshaled)
}
Expand Down
Loading

0 comments on commit ee1da4b

Please sign in to comment.