Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 61046c3

Browse files
authored
Merge pull request #979 from iotaledger/payload-nil-test
Fix panic when payload is nil
2 parents 1f0661e + 32da493 commit 61046c3

File tree

8 files changed

+92
-44
lines changed

8 files changed

+92
-44
lines changed

components/restapi/core/node.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package core
22

3-
import "github.com/iotaledger/iota.go/v4/api"
3+
import (
4+
"github.com/iotaledger/iota.go/v4/api"
5+
)
46

57
func info() *api.InfoResponse {
68
return &api.InfoResponse{

pkg/protocol/sybilprotection/sybilprotectionv1/performance/performance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (t *Tracker) TrackCandidateBlock(block *blocks.Block) {
104104
t.mutex.Lock()
105105
defer t.mutex.Unlock()
106106

107-
if block.Payload().PayloadType() != iotago.PayloadCandidacyAnnouncement {
107+
if payload := block.Payload(); payload == nil || payload.PayloadType() != iotago.PayloadCandidacyAnnouncement {
108108
return
109109
}
110110

pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (o *SybilProtection) TrackBlock(block *blocks.Block) {
113113
return
114114
}
115115

116-
if block.Payload().PayloadType() != iotago.PayloadCandidacyAnnouncement {
116+
if payload := block.Payload(); payload == nil || payload.PayloadType() != iotago.PayloadCandidacyAnnouncement {
117117
return
118118
}
119119

pkg/testsuite/snapshotcreator/snapshotcreator.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ func createGenesisOutput(api iotago.API, genesisTokenAmount iotago.BaseToken, ge
216216
return output, nil
217217
}
218218

219+
//nolint:nilnil // we want to return nil here
219220
return nil, nil
220221
}
221222

tools/docker-network/docker-compose.yml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ services:
3838
--prometheus.goMetrics=true
3939
--prometheus.processMetrics=true
4040
--debugAPI.enabled=true
41-
profiles:
42-
- minimal
43-
- full
4441
4542
node-2-validator:
4643
image: docker-network-node-1-validator:latest
@@ -275,9 +272,6 @@ services:
275272
--inx.address=node-1-validator:9029
276273
--restAPI.bindAddress=0.0.0.0:9091
277274
--restAPI.advertiseAddress=inx-indexer:9091
278-
profiles:
279-
- minimal
280-
- full
281275
282276
inx-mqtt:
283277
image: iotaledger/inx-mqtt:2.0-alpha
@@ -291,9 +285,6 @@ services:
291285
command: >
292286
--inx.address=node-1-validator:9029
293287
--mqtt.websocket.bindAddress=inx-mqtt:1888
294-
profiles:
295-
- minimal
296-
- full
297288
298289
inx-blockissuer:
299290
image: iotaledger/inx-blockissuer:1.0-alpha
@@ -313,9 +304,6 @@ services:
313304
--restAPI.bindAddress=inx-blockissuer:9086
314305
--blockIssuer.accountAddress=rms1prkursay9fs2qjmfctamd6yxg9x8r3ry47786x0mvwek4qr9xd9d5c6gkun
315306
--blockIssuer.proofOfWork.targetTrailingZeros=5
316-
profiles:
317-
- minimal
318-
- full
319307
320308
inx-faucet:
321309
image: iotaledger/inx-faucet:2.0-alpha
@@ -343,9 +331,6 @@ services:
343331
--faucet.baseTokenAmountMaxTarget=5000000000
344332
--faucet.manaAmount=100000000
345333
--faucet.manaAmountMinFaucet=1000000000
346-
profiles:
347-
- minimal
348-
- full
349334
350335
inx-validator-1:
351336
image: iotaledger/inx-validator:1.0-alpha
@@ -365,9 +350,6 @@ services:
365350
--validator.accountAddress=rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6
366351
--validator.candidacyRetryInterval=${CANDIDACY_RETRY_INTERVAL:-10s}
367352
--validator.issueCandidacyPayload=${ISSUE_CANDIDACY_PAYLOAD_V1:-true}
368-
profiles:
369-
- minimal
370-
- full
371353
372354
inx-validator-2:
373355
image: iotaledger/inx-validator:1.0-alpha
@@ -447,9 +429,6 @@ services:
447429
- "--dashboard.auth.username=${DASHBOARD_USERNAME:-admin}"
448430
- "--dashboard.auth.passwordHash=${DASHBOARD_PASSWORD:-0000000000000000000000000000000000000000000000000000000000000000}"
449431
- "--dashboard.auth.passwordSalt=${DASHBOARD_SALT:-0000000000000000000000000000000000000000000000000000000000000000}"
450-
profiles:
451-
- minimal
452-
- full
453432

454433
inx-dashboard-2:
455434
container_name: inx-dashboard-2

tools/docker-network/run.sh

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
11
#!/bin/bash
22

33
# Create a function to join an array of strings by a given character
4-
function join { local IFS="$1"; shift; echo "$*"; }
4+
function join {
5+
local IFS="$1"
6+
shift
7+
echo "$*"
8+
}
59

610
# Initialize variables
711
MONITORING=0
812
MINIMAL=0
913

1014
# Loop over all arguments
11-
for arg in "$@"
12-
do
13-
case $arg in
14-
monitoring=*)
15-
MONITORING="${arg#*=}"
16-
shift
17-
;;
18-
minimal=*)
19-
MINIMAL="${arg#*=}"
20-
shift
21-
;;
22-
*)
23-
# Unknown option
24-
echo "Unknown argument: $arg"
25-
echo 'Call with ./run.sh [monitoring=0|1] [minimal=0|1]'
26-
exit 1
27-
;;
28-
esac
15+
for arg in "$@"; do
16+
case $arg in
17+
monitoring=*)
18+
MONITORING="${arg#*=}"
19+
shift
20+
;;
21+
minimal=*)
22+
MINIMAL="${arg#*=}"
23+
shift
24+
;;
25+
*)
26+
# Unknown option
27+
echo "Unknown argument: $arg"
28+
echo 'Call with ./run.sh [monitoring=0|1] [minimal=0|1]'
29+
exit 1
30+
;;
31+
esac
2932
done
3033

3134
export DOCKER_BUILDKIT=1
@@ -94,14 +97,14 @@ if [ $MONITORING -ne 0 ]; then
9497
fi
9598

9699
if [ $MINIMAL -ne 0 ]; then
97-
PROFILES+=("minimal")
98100
echo "Minimal profile active"
99101
else
100102
PROFILES+=("full")
101103
echo "Full profile active"
102104
fi
103105

104106
export COMPOSE_PROFILES=$(join , ${PROFILES[@]})
107+
105108
docker compose up
106109

107110
echo "Clean up docker resources"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//go:build dockertests
2+
3+
package tests
4+
5+
import (
6+
"context"
7+
"fmt"
8+
"testing"
9+
10+
"github.com/stretchr/testify/require"
11+
12+
"github.com/iotaledger/hive.go/lo"
13+
"github.com/iotaledger/iota-core/pkg/testsuite/mock"
14+
"github.com/iotaledger/iota-core/tools/docker-network/tests/dockertestframework"
15+
)
16+
17+
// Test_AccountTransitions follows the account state transition flow described in:
18+
// 1. Create account-1.
19+
// 2. Create account-2.
20+
// 3. account-1 requests faucet funds then allots 1000 mana to account-2.
21+
// 4. account-2 requests faucet funds then creates native tokens.
22+
func Test_Payload_Nil_Test(t *testing.T) {
23+
d := dockertestframework.NewDockerTestFramework(t,
24+
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptionsFunc()...),
25+
)
26+
defer d.Stop()
27+
28+
d.AddValidatorNode("V1", "docker-network-inx-validator-1-1", "http://localhost:8050", "rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6")
29+
d.AddValidatorNode("V2", "docker-network-inx-validator-2-1", "http://localhost:8060", "rms1pqm4xk8e9ny5w5rxjkvtp249tfhlwvcshyr3pc0665jvp7g3hc875k538hl")
30+
d.AddValidatorNode("V3", "docker-network-inx-validator-3-1", "http://localhost:8070", "rms1pp4wuuz0y42caz48vv876qfpmffswsvg40zz8v79sy8cp0jfxm4kunflcgt")
31+
d.AddValidatorNode("V4", "docker-network-inx-validator-4-1", "http://localhost:8040", "rms1pr8cxs3dzu9xh4cduff4dd4cxdthpjkpwmz2244f75m0urslrsvtsshrrjw")
32+
d.AddNode("node5", "docker-network-node-5-1", "http://localhost:8080")
33+
34+
err := d.Run()
35+
require.NoError(t, err)
36+
37+
d.WaitUntilNetworkReady()
38+
39+
ctx, cancel := context.WithCancel(context.Background())
40+
41+
// cancel the context when the test is done
42+
t.Cleanup(cancel)
43+
44+
// create account-1
45+
accounts := d.CreateAccountsFromFaucet(ctx, 2, "account-1", "account-2")
46+
account1 := accounts[0]
47+
account2 := accounts[1]
48+
49+
// allot 1000 mana from account-1 to account-2
50+
fmt.Println("Allotting mana from account-1 to account-2")
51+
d.RequestFaucetFundsAndAllotManaTo(account1.Wallet(), account2.Account(), 1000)
52+
53+
// create native token
54+
fmt.Println("Creating native token")
55+
d.CreateNativeToken(account1.Wallet(), 5_000_000, 10_000_000_000)
56+
57+
blk := lo.PanicOnErr(account1.Wallet().CreateBasicBlock(ctx, "something", mock.WithPayload(nil)))
58+
d.SubmitBlock(ctx, blk.ProtocolBlock())
59+
60+
d.AwaitEpochFinalized()
61+
}

tools/docker-network/tests/run_tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ mkdir -p docker-network-snapshots/
2020
# Allow 'others' to write, so a snapshot can be created via the management API from within docker containers.
2121
chmod o+w docker-network-snapshots/
2222

23+
export COMPOSE_PROFILES="full"
24+
2325
# Allow docker compose to build and cache an image
2426
docker compose build --build-arg DOCKER_BUILD_CONTEXT=${DOCKER_BUILD_CONTEXT} --build-arg DOCKERFILE_PATH=${DOCKERFILE_PATH}
2527

0 commit comments

Comments
 (0)