コード例 #1
0
ファイル: main_test.go プロジェクト: zenododobird/horizon
func TestAssets(t *testing.T) {
	Convey("Parse", t, func() {
		var (
			result xdr.AssetType
			err    error
		)

		result, err = Parse("native")
		So(result, ShouldEqual, xdr.AssetTypeAssetTypeNative)
		So(err, ShouldBeNil)

		result, err = Parse("credit_alphanum4")
		So(result, ShouldEqual, xdr.AssetTypeAssetTypeCreditAlphanum4)
		So(err, ShouldBeNil)

		result, err = Parse("credit_alphanum12")
		So(result, ShouldEqual, xdr.AssetTypeAssetTypeCreditAlphanum12)
		So(err, ShouldBeNil)

		result, err = Parse("not_real")
		So(errors.Is(err, ErrInvalidString), ShouldBeTrue)

		result, err = Parse("")
		So(errors.Is(err, ErrInvalidString), ShouldBeTrue)
	})

	Convey("String", t, func() {
		var (
			result string
			err    error
		)

		result, err = String(xdr.AssetTypeAssetTypeNative)
		So(result, ShouldEqual, "native")
		So(err, ShouldBeNil)

		result, err = String(xdr.AssetTypeAssetTypeCreditAlphanum4)
		So(result, ShouldEqual, "credit_alphanum4")
		So(err, ShouldBeNil)

		result, err = String(xdr.AssetTypeAssetTypeCreditAlphanum12)
		So(result, ShouldEqual, "credit_alphanum12")
		So(err, ShouldBeNil)

		result, err = String(xdr.AssetType(15))
		So(errors.Is(err, ErrInvalidValue), ShouldBeTrue)
	})
}
コード例 #2
0
ファイル: resource_offer.go プロジェクト: raymens/horizon
// NewOfferAssetResource creates a new OfferAssetResource, ensuring that
// the code and issuer are consistent.  If both are null, we return a native
// asset type.
func NewOfferAssetResource(aType int32, code sql.NullString, issuer sql.NullString) OfferAssetResource {
	result := OfferAssetResource{
		Code:   code.String,
		Issuer: issuer.String,
	}

	switch xdr.AssetType(aType) {
	case xdr.AssetTypeAssetTypeNative:
		result.Type = "native"
	case xdr.AssetTypeAssetTypeCreditAlphanum4:
		result.Type = "credit_alphanum4"
	case xdr.AssetTypeAssetTypeCreditAlphanum12:
		result.Type = "credit_alphanum12"
	default:
		result.Type = fmt.Sprintf("unknown:%d", aType)
	}

	return result
}