コード例 #1
0
ファイル: actions_root_test.go プロジェクト: irisli/horizon
func TestRootAction(t *testing.T) {

	Convey("GET /", t, func() {
		test.LoadScenario("base")
		server := test.NewStaticMockServer(`{
				"info": {
					"network": "test",
					"build": "test-core"
				}
			}`)
		defer server.Close()
		app := NewTestApp()
		app.horizonVersion = "test-horizon"
		app.config.StellarCoreURL = server.URL

		defer app.Close()
		rh := NewRequestHelper(app)

		w := rh.Get("/", test.RequestHelperNoop)

		So(w.Code, ShouldEqual, 200)

		var result resource.Root
		err := json.Unmarshal(w.Body.Bytes(), &result)
		So(err, ShouldBeNil)

		So(result.HorizonVersion, ShouldEqual, "test-horizon")
		So(result.StellarCoreVersion, ShouldEqual, "test-core")

	})
}
コード例 #2
0
ファイル: submitter_test.go プロジェクト: FihlaTV/horizon
func TestDefaultSubmitter(t *testing.T) {
	ctx := test.Context()

	Convey("submitter (The default Submitter implementation)", t, func() {

		Convey("submits to the configured stellar-core instance correctly", func() {
			server := test.NewStaticMockServer(`{
				"status": "PENDING",
				"error": null
				}`)
			defer server.Close()

			s := NewDefaultSubmitter(http.DefaultClient, server.URL)
			sr := s.Submit(ctx, "hello")
			So(sr.Err, ShouldBeNil)
			So(sr.Duration, ShouldBeGreaterThan, 0)
			So(server.LastRequest.URL.Query().Get("blob"), ShouldEqual, "hello")
		})

		Convey("succeeds when the stellar-core responds with DUPLICATE status", func() {
			server := test.NewStaticMockServer(`{
				"status": "DUPLICATE",
				"error": null
				}`)
			defer server.Close()

			s := NewDefaultSubmitter(http.DefaultClient, server.URL)
			sr := s.Submit(ctx, "hello")
			So(sr.Err, ShouldBeNil)
		})

		Convey("errors when the stellar-core url is empty", func() {
			s := NewDefaultSubmitter(http.DefaultClient, "")
			sr := s.Submit(ctx, "hello")
			So(sr.Err, ShouldNotBeNil)
		})

		Convey("errors when the stellar-core url is not parseable", func() {
			s := NewDefaultSubmitter(http.DefaultClient, "http://Not a url")
			sr := s.Submit(ctx, "hello")
			So(sr.Err, ShouldNotBeNil)
		})

		Convey("errors when the stellar-core url is not reachable", func() {
			s := NewDefaultSubmitter(http.DefaultClient, "http://127.0.0.1:65535")
			sr := s.Submit(ctx, "hello")
			So(sr.Err, ShouldNotBeNil)
		})

		Convey("errors when the stellar-core returns an unparseable response", func() {
			server := test.NewStaticMockServer(`{`)
			defer server.Close()

			s := NewDefaultSubmitter(http.DefaultClient, server.URL)
			sr := s.Submit(ctx, "hello")
			So(sr.Err, ShouldNotBeNil)
		})

		Convey("errors when the stellar-core returns an exception response", func() {
			server := test.NewStaticMockServer(`{"exception": "Invalid XDR"}`)
			defer server.Close()

			s := NewDefaultSubmitter(http.DefaultClient, server.URL)
			sr := s.Submit(ctx, "hello")
			So(sr.Err, ShouldNotBeNil)
			So(sr.Err.Error(), ShouldContainSubstring, "Invalid XDR")
		})

		Convey("errors when the stellar-core returns an unrecognized status", func() {
			server := test.NewStaticMockServer(`{"status": "NOTREAL"}`)
			defer server.Close()

			s := NewDefaultSubmitter(http.DefaultClient, server.URL)
			sr := s.Submit(ctx, "hello")
			So(sr.Err, ShouldNotBeNil)
			So(sr.Err.Error(), ShouldContainSubstring, "NOTREAL")
		})

		Convey("errors when the stellar-core returns an error response", func() {
			server := test.NewStaticMockServer(`{"status": "ERROR", "error": "1234"}`)
			defer server.Close()

			s := NewDefaultSubmitter(http.DefaultClient, server.URL)
			sr := s.Submit(ctx, "hello")
			So(sr.Err, ShouldHaveSameTypeAs, &FailedTransactionError{})
			ferr := sr.Err.(*FailedTransactionError)
			So(ferr.ResultXDR, ShouldEqual, "1234")
		})
	})
}