gitlab.com/jokerrs1/Sia@v1.3.2/siatest/testgroup_test.go (about) 1 package siatest 2 3 import ( 4 "testing" 5 6 "github.com/NebulousLabs/Sia/build" 7 ) 8 9 // TestCreateTestGroup tests the behavior of NewGroup. 10 func TestNewGroup(t *testing.T) { 11 if testing.Short() { 12 t.SkipNow() 13 } 14 // Specify the parameters for the group 15 groupParams := GroupParams{ 16 Hosts: 5, 17 Renters: 2, 18 Miners: 2, 19 } 20 // Create the group 21 tg, err := NewGroupFromTemplate(groupParams) 22 if err != nil { 23 t.Fatal("Failed to create group: ", err) 24 } 25 defer func() { 26 if err := tg.Close(); err != nil { 27 t.Fatal(err) 28 } 29 }() 30 31 // Check if the correct number of nodes was created 32 if len(tg.Hosts()) != groupParams.Hosts { 33 t.Error("Wrong number of hosts") 34 } 35 if len(tg.Renters()) != groupParams.Renters { 36 t.Error("Wrong number of renters") 37 } 38 if len(tg.Miners()) != groupParams.Miners { 39 t.Error("Wrong number of miners") 40 } 41 if len(tg.Nodes()) != groupParams.Hosts+groupParams.Renters+groupParams.Miners { 42 t.Error("Wrong number of nodes") 43 } 44 45 // Check if nodes are funded 46 cg, err := tg.Nodes()[0].ConsensusGet() 47 if err != nil { 48 t.Fatal("Failed to get consensus: ", err) 49 } 50 for _, node := range tg.Nodes() { 51 wtg, err := node.WalletTransactionsGet(0, cg.Height) 52 if err != nil { 53 t.Fatal(err) 54 } 55 if len(wtg.ConfirmedTransactions) == 0 { 56 t.Errorf("Node has 0 confirmed funds") 57 } 58 } 59 } 60 61 // TestCreateTestGroup tests NewGroup without a miner 62 func TestNewGroupNoMiner(t *testing.T) { 63 if testing.Short() || !build.VLONG { 64 t.SkipNow() 65 } 66 // Try to create a group without miners 67 groupParams := GroupParams{ 68 Hosts: 5, 69 Renters: 2, 70 Miners: 0, 71 } 72 // Create the group 73 _, err := NewGroupFromTemplate(groupParams) 74 if err == nil { 75 t.Fatal("Creating a group without miners should fail: ", err) 76 } 77 } 78 79 // TestCreateTestGroup tests NewGroup with no renter or host 80 func TestNewGroupNoRenterHost(t *testing.T) { 81 if testing.Short() || !build.VLONG { 82 t.SkipNow() 83 } 84 // Create a group with nothing but miners 85 groupParams := GroupParams{ 86 Hosts: 0, 87 Renters: 0, 88 Miners: 5, 89 } 90 // Create the group 91 tg, err := NewGroupFromTemplate(groupParams) 92 if err != nil { 93 t.Fatal("Failed to create group: ", err) 94 } 95 func() { 96 if err := tg.Close(); err != nil { 97 t.Fatal(err) 98 } 99 }() 100 }