Example #1
0
func TestSplit(t *testing.T) {
	cases := []struct {
		CaseName       string
		Address        string
		ExpectedName   string
		ExpectedDomain string
		ExpectedError  error
	}{
		{"happy path", "scott*stellar.org", "scott", "stellar.org", nil},
		{"blank", "", "", "", ErrInvalidAddress},
		{"blank name", "*stellar.org", "", "", ErrInvalidName},
		{"blank domain", "scott*", "", "", ErrInvalidDomain},
		{"invalid domain", "scott*--3.com", "", "", ErrInvalidDomain},
	}

	for _, c := range cases {
		name, domain, err := Split(c.Address)

		if c.ExpectedError == nil {
			assert.Equal(t, name, c.ExpectedName)
			assert.Equal(t, domain, c.ExpectedDomain)
		} else {
			assert.Equal(t, errors.Cause(err), c.ExpectedError)
		}
	}
}
Example #2
0
func run(cmd *cobra.Command, args []string) {
	var (
		cfg     Config
		cfgPath = cmd.PersistentFlags().Lookup("conf").Value.String()
	)
	log.SetLevel(log.InfoLevel)
	err := config.Read(cfgPath, &cfg)

	if err != nil {
		switch cause := errors.Cause(err).(type) {
		case *config.InvalidConfigError:
			log.Error("config file: ", cause)
		default:
			log.Error(err)
		}
		os.Exit(1)
	}

	driver, err := initDriver(cfg)
	if err != nil {
		log.Error(err)
		os.Exit(1)
	}

	mux := initMux(driver)
	addr := fmt.Sprintf("0.0.0.0:%d", cfg.Port)

	http.Run(http.Config{
		ListenAddr: addr,
		Handler:    mux,
		OnStarting: func() {
			log.Infof("starting federation server - %s", app.Version())
			log.Infof("listening on %s", addr)
		},
	})
}
Example #3
0
				ReturnString(200, submitResponse)

			account, err := client.SubmitTransaction(tx)
			Expect(err).To(BeNil())
			Expect(account.Ledger).To(Equal(int32(3128812)))
		})

		It("failure response", func() {
			hmock.
				On("POST", "https://localhost/transactions").
				ReturnString(400, transactionFailure)

			_, err := client.SubmitTransaction(tx)
			Expect(err).NotTo(BeNil())
			Expect(err.Error()).To(ContainSubstring("Horizon error"))
			horizonError, ok := errors.Cause(err).(*Error)
			Expect(ok).To(BeTrue())
			Expect(horizonError.Problem.Title).To(Equal("Transaction Failed"))
		})

		It("connection error", func() {
			hmock.
				On("POST", "https://localhost/transactions").
				ReturnError("http.Client error")

			_, err := client.SubmitTransaction(tx)
			Expect(err).NotTo(BeNil())
			Expect(err.Error()).To(ContainSubstring("http.Client error"))
			_, ok := err.(*Error)
			Expect(ok).To(BeFalse())
		})