Skip to content

Commit

Permalink
Use predefined set of protocol parameters for all docker tests to inc…
Browse files Browse the repository at this point in the history
…rease execution speed
  • Loading branch information
muXxer committed May 9, 2024
1 parent 8055580 commit 157bf60
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 141 deletions.
10 changes: 2 additions & 8 deletions tools/docker-network/tests/accounttransition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ package tests
import (
"fmt"
"testing"
"time"

"github.com/stretchr/testify/require"

"github.com/iotaledger/iota-core/tools/docker-network/tests/dockertestframework"
iotago "github.com/iotaledger/iota.go/v4"
)

// Test_AccountTransitions follows the account state transition flow described in:
Expand All @@ -20,12 +18,8 @@ import (
// 4. account2 requests faucet funds then creates native tokens.
func Test_AccountTransitions(t *testing.T) {
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(5, time.Now().Unix(), 10, 4),
iotago.WithLivenessOptions(10, 10, 2, 4, 8),
iotago.WithRewardsOptions(8, 10, 2, 384),
iotago.WithTargetCommitteeSize(4),
))
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptions...),
)
defer d.Stop()

d.AddValidatorNode("V1", "docker-network-inx-validator-1-1", "http://localhost:8050", "rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6")
Expand Down
41 changes: 15 additions & 26 deletions tools/docker-network/tests/api_core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,8 @@ func prepareAssets(d *dockertestframework.DockerTestFramework, totalAssetsNum in
// 5. Wait until next epoch then check again if the results remain.
func Test_ValidatorsAPI(t *testing.T) {
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(5, time.Now().Unix(), 10, 4),
iotago.WithLivenessOptions(10, 10, 2, 4, 8),
iotago.WithRewardsOptions(8, 10, 2, 384),
iotago.WithTargetCommitteeSize(4),
))
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptions...),
)
defer d.Stop()

d.AddValidatorNode("V1", "docker-network-inx-validator-1-1", "http://localhost:8050", "rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6")
Expand All @@ -274,10 +270,11 @@ func Test_ValidatorsAPI(t *testing.T) {
d.AddValidatorNode("V4", "docker-network-inx-validator-4-1", "http://localhost:8040", "rms1pr8cxs3dzu9xh4cduff4dd4cxdthpjkpwmz2244f75m0urslrsvtsshrrjw")
d.AddNode("node5", "docker-network-node-5-1", "http://localhost:8080")

runErr := d.Run()
require.NoError(t, runErr)
err := d.Run()
require.NoError(t, err)

d.WaitUntilNetworkReady()

hrp := d.DefaultWallet().Client.CommittedAPI().ProtocolParameters().Bech32HRP()

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -329,14 +326,10 @@ func Test_ValidatorsAPI(t *testing.T) {
require.ElementsMatch(t, expectedValidators, actualValidators)
}

func Test_CoreAPI(t *testing.T) {
func Test_CoreAPI_ValidRequests(t *testing.T) {
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(5, time.Now().Unix(), 10, 4),
iotago.WithLivenessOptions(10, 10, 2, 4, 8),
iotago.WithRewardsOptions(8, 10, 2, 384),
iotago.WithTargetCommitteeSize(4),
))
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptions...),
)
defer d.Stop()

d.AddValidatorNode("V1", "docker-network-inx-validator-1-1", "http://localhost:8050", "rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6")
Expand All @@ -345,8 +338,8 @@ func Test_CoreAPI(t *testing.T) {
d.AddValidatorNode("V4", "docker-network-inx-validator-4-1", "http://localhost:8040", "rms1pr8cxs3dzu9xh4cduff4dd4cxdthpjkpwmz2244f75m0urslrsvtsshrrjw")
d.AddNode("node5", "docker-network-node-5-1", "http://localhost:8080")

runErr := d.Run()
require.NoError(t, runErr)
err := d.Run()
require.NoError(t, err)

d.WaitUntilNetworkReady()

Expand Down Expand Up @@ -676,12 +669,8 @@ func Test_CoreAPI(t *testing.T) {

func Test_CoreAPI_BadRequests(t *testing.T) {
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(5, time.Now().Unix(), 10, 4),
iotago.WithLivenessOptions(10, 10, 2, 4, 8),
iotago.WithRewardsOptions(8, 10, 2, 384),
iotago.WithTargetCommitteeSize(4),
))
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptions...),
)
defer d.Stop()

d.AddValidatorNode("V1", "docker-network-inx-validator-1-1", "http://localhost:8050", "rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6")
Expand All @@ -690,8 +679,8 @@ func Test_CoreAPI_BadRequests(t *testing.T) {
d.AddValidatorNode("V4", "docker-network-inx-validator-4-1", "http://localhost:8040", "rms1pr8cxs3dzu9xh4cduff4dd4cxdthpjkpwmz2244f75m0urslrsvtsshrrjw")
d.AddNode("node5", "docker-network-node-5-1", "http://localhost:8080")

runErr := d.Run()
require.NoError(t, runErr)
err := d.Run()
require.NoError(t, err)

d.WaitUntilNetworkReady()

Expand Down Expand Up @@ -872,7 +861,7 @@ func Test_CoreAPI_BadRequests(t *testing.T) {
{
name: "Test_Committee_Failure",
testFunc: func(t *testing.T, node *dockertestframework.Node, client mock.Client) {
resp, err := client.Committee(context.Background(), 4)
resp, err := client.Committee(context.Background(), 4000)
require.Error(t, err)
require.True(t, dockertestframework.IsStatusCode(err, http.StatusBadRequest))
require.Nil(t, resp)
Expand Down
54 changes: 17 additions & 37 deletions tools/docker-network/tests/api_management_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/iotaledger/iota-core/pkg/storage/database"
"github.com/iotaledger/iota-core/tools/docker-network/tests/dockertestframework"
iotago "github.com/iotaledger/iota.go/v4"
"github.com/iotaledger/iota.go/v4/api"
)

Expand All @@ -22,21 +21,17 @@ func getContextWithTimeout(duration time.Duration) context.Context {
return ctx
}

// Test_ManagementAPI_Peers tests if the peer management API returns the expected results.
// Test_ManagementAPI_Peers_ValidRequests tests if the peer management API returns the expected results.
// 1. Run docker network.
// 2. List all peers of node 1.
// 3. Delete a peer from node 1.
// 4. List all peers of node 1 again and check if the peer was deleted.
// 5. Re-Add the peer to node 1.
// 6. List all peers of node 1 again and check if the peer was added.
func Test_ManagementAPI_Peers(t *testing.T) {
func Test_ManagementAPI_Peers_ValidRequests(t *testing.T) {
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(5, time.Now().Unix(), 10, 4),
iotago.WithLivenessOptions(10, 10, 2, 4, 8),
iotago.WithRewardsOptions(8, 10, 2, 384),
iotago.WithTargetCommitteeSize(4),
))
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptions...),
)
defer d.Stop()

d.AddValidatorNode("V1", "docker-network-inx-validator-1-1", "http://localhost:8050", "rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6")
Expand All @@ -45,8 +40,8 @@ func Test_ManagementAPI_Peers(t *testing.T) {
d.AddValidatorNode("V4", "docker-network-inx-validator-4-1", "http://localhost:8040", "rms1pr8cxs3dzu9xh4cduff4dd4cxdthpjkpwmz2244f75m0urslrsvtsshrrjw")
d.AddNode("node5", "docker-network-node-5-1", "http://localhost:8080")

runErr := d.Run()
require.NoError(t, runErr)
err := d.Run()
require.NoError(t, err)

d.WaitUntilNetworkReady()

Expand Down Expand Up @@ -120,12 +115,8 @@ func Test_ManagementAPI_Peers(t *testing.T) {

func Test_ManagementAPI_Peers_BadRequests(t *testing.T) {
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(5, time.Now().Unix(), 10, 4),
iotago.WithLivenessOptions(10, 10, 2, 4, 8),
iotago.WithRewardsOptions(8, 10, 2, 384),
iotago.WithTargetCommitteeSize(4),
))
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptions...),
)
defer d.Stop()

d.AddValidatorNode("V1", "docker-network-inx-validator-1-1", "http://localhost:8050", "rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6")
Expand All @@ -134,8 +125,8 @@ func Test_ManagementAPI_Peers_BadRequests(t *testing.T) {
d.AddValidatorNode("V4", "docker-network-inx-validator-4-1", "http://localhost:8040", "rms1pr8cxs3dzu9xh4cduff4dd4cxdthpjkpwmz2244f75m0urslrsvtsshrrjw")
d.AddNode("node5", "docker-network-node-5-1", "http://localhost:8080")

runErr := d.Run()
require.NoError(t, runErr)
err := d.Run()
require.NoError(t, err)

d.WaitUntilNetworkReady()

Expand Down Expand Up @@ -184,13 +175,7 @@ func Test_ManagementAPI_Peers_BadRequests(t *testing.T) {

func Test_ManagementAPI_Pruning(t *testing.T) {
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(0, time.Now().Unix(), 10, 3),
iotago.WithLivenessOptions(10, 10, 2, 4, 5),
iotago.WithCongestionControlOptions(1, 1, 1, 400_000, 250_000, 50_000_000, 1000, 100),
iotago.WithRewardsOptions(8, 10, 2, 384),
iotago.WithTargetCommitteeSize(4),
),
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptions...),
)
defer d.Stop()

Expand All @@ -200,8 +185,8 @@ func Test_ManagementAPI_Pruning(t *testing.T) {
d.AddValidatorNode("V4", "docker-network-inx-validator-4-1", "http://localhost:8040", "rms1pr8cxs3dzu9xh4cduff4dd4cxdthpjkpwmz2244f75m0urslrsvtsshrrjw")
d.AddNode("node5", "docker-network-node-5-1", "http://localhost:8080")

runErr := d.Run()
require.NoError(t, runErr)
err := d.Run()
require.NoError(t, err)

d.WaitUntilNetworkReady()

Expand Down Expand Up @@ -265,13 +250,8 @@ func Test_ManagementAPI_Pruning(t *testing.T) {

func Test_ManagementAPI_Snapshots(t *testing.T) {
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(0, time.Now().Unix(), 10, 3),
iotago.WithLivenessOptions(10, 10, 2, 4, 5),
iotago.WithCongestionControlOptions(1, 1, 1, 400_000, 250_000, 50_000_000, 1000, 100),
iotago.WithRewardsOptions(8, 10, 2, 384),
iotago.WithTargetCommitteeSize(4),
))
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptions...),
)
defer d.Stop()

d.AddValidatorNode("V1", "docker-network-inx-validator-1-1", "http://localhost:8050", "rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6")
Expand All @@ -280,8 +260,8 @@ func Test_ManagementAPI_Snapshots(t *testing.T) {
d.AddValidatorNode("V4", "docker-network-inx-validator-4-1", "http://localhost:8040", "rms1pr8cxs3dzu9xh4cduff4dd4cxdthpjkpwmz2244f75m0urslrsvtsshrrjw")
d.AddNode("node5", "docker-network-node-5-1", "http://localhost:8080")

runErr := d.Run()
require.NoError(t, runErr)
err := d.Run()
require.NoError(t, err)

d.WaitUntilNetworkReady()

Expand Down
40 changes: 10 additions & 30 deletions tools/docker-network/tests/committeerotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ import (
// 5. Check that committee of size 4 is selected in next epoch.
func Test_SmallerCommittee(t *testing.T) {
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(5, time.Now().Unix(), 10, 4),
iotago.WithLivenessOptions(10, 10, 2, 4, 8),
iotago.WithRewardsOptions(8, 10, 2, 384),
iotago.WithTargetCommitteeSize(4),
))
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptions...),
)
defer d.Stop()

d.AddValidatorNode("V1", "docker-network-inx-validator-1-1", "http://localhost:8050", "rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6")
Expand Down Expand Up @@ -69,12 +65,8 @@ func Test_SmallerCommittee(t *testing.T) {
// 5. Check that committee of size 3 (V1, V2, V4) is selected in next epoch and finalization occurs again from that epoch.
func Test_ReuseDueToNoFinalization(t *testing.T) {
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(5, time.Now().Unix(), 10, 4),
iotago.WithLivenessOptions(10, 10, 2, 4, 8),
iotago.WithRewardsOptions(8, 10, 2, 384),
iotago.WithTargetCommitteeSize(4),
))
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptions...),
)
defer d.Stop()

d.AddValidatorNode("V1", "docker-network-inx-validator-1-1", "http://localhost:8050", "rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6")
Expand Down Expand Up @@ -138,12 +130,8 @@ func Test_ReuseDueToNoFinalization(t *testing.T) {
// 5. Check finalization advances and the committee is changed to 3 committee members.
func Test_NoCandidacyPayload(t *testing.T) {
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(5, time.Now().Unix(), 10, 4),
iotago.WithLivenessOptions(10, 10, 2, 4, 8),
iotago.WithRewardsOptions(8, 10, 2, 384),
iotago.WithTargetCommitteeSize(4),
))
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptions...),
)
defer d.Stop()

d.AddValidatorNode("V1", "docker-network-inx-validator-1-1", "http://localhost:8050", "rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6", false)
Expand Down Expand Up @@ -188,12 +176,8 @@ func Test_NoCandidacyPayload(t *testing.T) {
// 3. Check if the account became a staker.
func Test_Staking(t *testing.T) {
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(5, time.Now().Unix(), 10, 4),
iotago.WithLivenessOptions(10, 10, 2, 4, 8),
iotago.WithRewardsOptions(8, 10, 2, 384),
iotago.WithTargetCommitteeSize(3),
))
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptions...),
)
defer d.Stop()

d.AddValidatorNode("V1", "docker-network-inx-validator-1-1", "http://localhost:8050", "rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6")
Expand Down Expand Up @@ -231,12 +215,8 @@ func Test_Staking(t *testing.T) {
// 4. Delegate requested faucet funds to V3, V3 should replace V1 as a committee member. (V3 > V2 > V4 > V1)
func Test_Delegation(t *testing.T) {
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(5, time.Now().Unix(), 10, 4),
iotago.WithLivenessOptions(10, 10, 2, 4, 8),
iotago.WithRewardsOptions(8, 10, 2, 384),
iotago.WithTargetCommitteeSize(3),
))
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptions...),
)
defer d.Stop()

// V1 pubKey in hex: 0x293dc170d9a59474e6d81cfba7f7d924c09b25d7166bcfba606e53114d0a758b
Expand Down
4 changes: 2 additions & 2 deletions tools/docker-network/tests/dockertestframework/awaits.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ func (d *DockerTestFramework) AwaitFinalization(targetSlot iotago.SlotIndex) {
}

func (d *DockerTestFramework) AwaitEpochFinalized() {
//nolint:lostcancel
ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

info, err := d.defaultWallet.Client.Info(ctx)
require.NoError(d.Testing, err)
Expand Down
2 changes: 1 addition & 1 deletion tools/docker-network/tests/dockertestframework/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

func (d *DockerTestFramework) WaitUntilFaucetHealthy() {
fmt.Println("Wait until the faucet is healthy...")
defer fmt.Println("Wait until the faucet is healthy......done")
defer fmt.Println("Wait until the faucet is healthy... done!")

d.Eventually(func() error {
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, d.optsFaucetURL+"/health", nil)
Expand Down
4 changes: 2 additions & 2 deletions tools/docker-network/tests/dockertestframework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ func (d *DockerTestFramework) Stop() {
}

func (d *DockerTestFramework) StopContainer(containerName ...string) error {
fmt.Println("Stop validator", containerName, "......")
fmt.Println("Stopping container", containerName, "......")

args := append([]string{"stop"}, containerName...)

return exec.Command("docker", args...).Run()
}

func (d *DockerTestFramework) RestartContainer(containerName ...string) error {
fmt.Println("Restart validator", containerName, "......")
fmt.Println("Restarting container", containerName, "......")

args := append([]string{"restart"}, containerName...)

Expand Down
10 changes: 10 additions & 0 deletions tools/docker-network/tests/dockertestframework/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ var DefaultProtocolParametersOptions = []options.Option[iotago.V3ProtocolParamet
iotago.WithNetworkOptions(fmt.Sprintf("docker-tests-%d", time.Now().Unix()), iotago.PrefixTestnet),
}

// ShortSlotsAndEpochsProtocolParametersOptions sets the protocol parameters to have 5s slots and 40s epochs.
var ShortSlotsAndEpochsProtocolParametersOptions = []options.Option[iotago.V3ProtocolParameters]{
iotago.WithTimeProviderOptions(5, time.Now().Unix(), 5, 3),
iotago.WithLivenessOptions(5, 5, 2, 4, 5),
iotago.WithCongestionControlOptions(1, 1, 1, 200_000_000, 125_000_000, 50_000_000, 1000, 100),
iotago.WithRewardsOptions(8, 10, 2, 384),
iotago.WithStakingOptions(2, 5, 5),
iotago.WithTargetCommitteeSize(4),
}

// DefaultAccountOptions are the default snapshot options for the docker network.
func DefaultAccountOptions(protocolParams *iotago.V3ProtocolParameters) []options.Option[snapshotcreator.Options] {
return []options.Option[snapshotcreator.Options]{
Expand Down
6 changes: 2 additions & 4 deletions tools/docker-network/tests/eventapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ var eventAPITests = map[string]func(t *testing.T, e *dockertestframework.EventAP

func Test_MQTTTopics(t *testing.T) {
d := dockertestframework.NewDockerTestFramework(t,
dockertestframework.WithProtocolParametersOptions(
iotago.WithTimeProviderOptions(5, time.Now().Unix(), 10, 4),
iotago.WithLivenessOptions(10, 10, 2, 4, 8),
))
dockertestframework.WithProtocolParametersOptions(dockertestframework.ShortSlotsAndEpochsProtocolParametersOptions...),
)
defer d.Stop()

d.AddValidatorNode("V1", "docker-network-inx-validator-1-1", "http://localhost:8050", "rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6")
Expand Down
Loading

0 comments on commit 157bf60

Please sign in to comment.