func TestFinder(t *testing.T) { Convey("Finder", t, func() { test.LoadScenario("paths") conn := test.OpenDatabase(test.StellarCoreDatabaseUrl()) defer conn.Close() finder := &Finder{ Ctx: test.Context(), SqlQuery: db.SqlQuery{conn}, } native := makeAsset(xdr.AssetTypeAssetTypeNative, "", "") usd := makeAsset( xdr.AssetTypeAssetTypeCreditAlphanum4, "USD", "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN") eur := makeAsset( xdr.AssetTypeAssetTypeCreditAlphanum4, "EUR", "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN") Convey("Find", func() { query := paths.Query{ DestinationAddress: "GAEDTJ4PPEFVW5XV2S7LUXBEHNQMX5Q2GM562RJGOQG7GVCE5H3HIB4V", DestinationAsset: eur, DestinationAmount: xdr.Int64(200000000), SourceAssets: []xdr.Asset{usd}, } paths, err := finder.Find(query) So(err, ShouldBeNil) So(len(paths), ShouldEqual, 4) query.DestinationAmount = xdr.Int64(200000001) paths, err = finder.Find(query) So(err, ShouldBeNil) So(len(paths), ShouldEqual, 2) query.DestinationAmount = xdr.Int64(500000001) paths, err = finder.Find(query) So(err, ShouldBeNil) So(len(paths), ShouldEqual, 0) }) Convey("regression: paths that involve native currencies can be found", func() { query := paths.Query{ DestinationAddress: "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN", DestinationAsset: native, DestinationAmount: xdr.Int64(1), SourceAssets: []xdr.Asset{usd, native}, } paths, err := finder.Find(query) So(err, ShouldBeNil) So(len(paths), ShouldEqual, 2) }) }) }
func TestStreaming(t *testing.T) { ctx := test.Context() ctx, cancel := context.WithCancel(ctx) db := test.OpenDatabase(test.DatabaseUrl()) Convey("LedgerClosePump", t, func() { Convey("can cancel", func() { pump := NewLedgerClosePump(ctx, db) cancel() _, more := <-pump So(more, ShouldBeFalse) }) }) }
func TestStreaming(t *testing.T) { ctx, log := test.ContextWithLogBuffer() ctx, cancel := context.WithCancel(ctx) db := test.OpenDatabase(test.DatabaseUrl()) Convey("LedgerClosePump", t, func() { Convey("can cancel", func() { pump := NewLedgerClosePump(ctx, db) cancel() _, more := <-pump So(more, ShouldBeFalse) So(log.String(), ShouldContainSubstring, "canceling") }) }) }
func TestOrderBook(t *testing.T) { Convey("orderBook", t, func() { test.LoadScenario("paths") conn := test.OpenDatabase(test.StellarCoreDatabaseUrl()) defer conn.Close() ob := orderBook{ Selling: makeAsset( xdr.AssetTypeAssetTypeCreditAlphanum4, "EUR", "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN"), Buying: makeAsset( xdr.AssetTypeAssetTypeCreditAlphanum4, "USD", "GDSBCQO34HWPGUGQSP3QBFEXVTSR2PW46UIGTHVWGWJGQKH3AFNHXHXN"), DB: db.SqlQuery{conn}, } Convey("Cost", func() { r, err := ob.Cost(ob.Buying, 10) So(err, ShouldBeNil) So(r, ShouldEqual, xdr.Int64(10)) // this cost should consume the entire lowest priced order, whose price // is 1.0, thus the output should be the same r, err = ob.Cost(ob.Buying, 100000000) So(err, ShouldBeNil) So(r, ShouldEqual, xdr.Int64(100000000)) // now we are taking from the next offer, where the price is 2.0 r, err = ob.Cost(ob.Buying, 100000001) So(err, ShouldBeNil) So(r, ShouldEqual, xdr.Int64(100000002)) r, err = ob.Cost(ob.Buying, 500000000) So(err, ShouldBeNil) So(r, ShouldEqual, xdr.Int64(900000000)) r, err = ob.Cost(ob.Buying, 500000001) So(err, ShouldNotBeNil) }) }) }