Exemplo n.º 1
0
func TestParallelInitClose(t *testing.T) {
	// TODO: complete this
	conf := utils.NodeConfiguration{Type: "client", Name: "userthread"}
	RegisterClient(conf.Name, nil, conf.GetEnrollmentID(), conf.GetEnrollmentPWD())

	done := make(chan bool)

	n := 10
	for i := 0; i < n; i++ {
		go func() {
			for i := 0; i < 5; i++ {
				client, err := InitClient(conf.Name, nil)
				if err != nil {
					t.Log("Init failed")
				}

				cis := &obc.ChaincodeInvocationSpec{
					ChaincodeSpec: &obc.ChaincodeSpec{
						Type:                 obc.ChaincodeSpec_GOLANG,
						ChaincodeID:          &obc.ChaincodeID{Path: "Contract001"},
						CtorMsg:              nil,
						ConfidentialityLevel: obc.ConfidentialityLevel_CONFIDENTIAL,
					},
				}
				for i := 0; i < 20; i++ {
					uuid := util.GenerateUUID()
					client.NewChaincodeExecute(cis, uuid)
				}

				err = CloseClient(client)
				if err != nil {
					t.Log("Close failed")
				}
			}
			done <- true

		}()
	}
	for i := 0; i < n; i++ {
		log.Info("Waiting")
		<-done
		log.Info("+1")
	}
	log.Info("Test Finished!")
	//
}
Exemplo n.º 2
0
func initValidators() error {
	// Register
	conf := utils.NodeConfiguration{Type: "validator", Name: "validator"}
	err := RegisterValidator(conf.Name, ksPwd, conf.GetEnrollmentID(), conf.GetEnrollmentPWD())
	if err != nil {
		return err
	}

	// Verify that a second call to Register fails
	err = RegisterValidator(conf.Name, ksPwd, conf.GetEnrollmentID(), conf.GetEnrollmentPWD())
	if err != nil {
		return err
	}

	// Init
	validator, err = InitValidator(conf.Name, ksPwd)
	if err != nil {
		return err
	}

	err = RegisterValidator(conf.Name, ksPwd, conf.GetEnrollmentID(), conf.GetEnrollmentPWD())
	if err != nil {
		return err
	}

	return err
}
Exemplo n.º 3
0
func initClients() error {
	// Deployer
	deployerConf := utils.NodeConfiguration{Type: "client", Name: "user1"}
	if err := RegisterClient(deployerConf.Name, ksPwd, deployerConf.GetEnrollmentID(), deployerConf.GetEnrollmentPWD()); err != nil {
		return err
	}
	var err error
	deployer, err = InitClient(deployerConf.Name, ksPwd)
	if err != nil {
		return err
	}

	// Invoker
	invokerConf := utils.NodeConfiguration{Type: "client", Name: "user2"}
	if err := RegisterClient(invokerConf.Name, ksPwd, invokerConf.GetEnrollmentID(), invokerConf.GetEnrollmentPWD()); err != nil {
		return err
	}
	invoker, err = InitClient(invokerConf.Name, ksPwd)
	if err != nil {
		return err
	}

	return nil
}
Exemplo n.º 4
0
func TestRegistrationSameEnrollIDDifferentRole(t *testing.T) {
	conf := utils.NodeConfiguration{Type: "client", Name: "TestRegistrationSameEnrollIDDifferentRole"}
	if err := RegisterClient(conf.Name, nil, conf.GetEnrollmentID(), conf.GetEnrollmentPWD()); err != nil {
		t.Fatalf("Failed client registration [%s]", err)
	}

	if err := RegisterValidator(conf.Name, nil, conf.GetEnrollmentID(), conf.GetEnrollmentPWD()); err == nil {
		t.Fatal("Reusing the same enrollment id must be forbidden", err)
	}

	if err := RegisterPeer(conf.Name, nil, conf.GetEnrollmentID(), conf.GetEnrollmentPWD()); err == nil {
		t.Fatal("Reusing the same enrollment id must be forbidden", err)
	}
}