Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/test/kotlin/org/stellar/sdk/MemoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MemoTest :
val memo = Memo.none()
memo.toXdr().discriminant shouldBe MemoType.MEMO_NONE
memo.toString() shouldBe ""
Memo.fromXdr(memo.toXdr()) shouldBe memo
}
}

Expand All @@ -24,6 +25,7 @@ class MemoTest :
memo.text shouldBe "test"
memo.bytes shouldBe "test".toByteArray(StandardCharsets.UTF_8)
memo.toString() shouldBe "test"
Memo.fromXdr(memo.toXdr()) shouldBe memo
}

test("should create text memo from empty string") {
Expand All @@ -32,6 +34,10 @@ class MemoTest :
memo.text shouldBe ""
memo.bytes shouldBe "".toByteArray(StandardCharsets.UTF_8)
memo.toString() shouldBe ""
Memo.fromXdr(memo.toXdr()) shouldBe memo

// https://discord.com/channels/897514728459468821/1082043640140017664/1397339401713094778
org.stellar.sdk.xdr.Memo.fromXdrBase64(memo.toXdr().toXdrBase64())
}

test("should create text memo with UTF-8 content") {
Expand All @@ -40,6 +46,7 @@ class MemoTest :
memo.text shouldBe "三"
memo.bytes shouldBe "三".toByteArray(StandardCharsets.UTF_8)
memo.toString() shouldBe "三"
Memo.fromXdr(memo.toXdr()) shouldBe memo
}

test("should create text memo with exactly 28 bytes") {
Expand All @@ -50,6 +57,7 @@ class MemoTest :
memo.text shouldBe text
memo.bytes shouldBe text.toByteArray(StandardCharsets.UTF_8)
memo.toString() shouldBe text
Memo.fromXdr(memo.toXdr()) shouldBe memo
}

test("should throw exception when text is too long") {
Expand All @@ -74,6 +82,7 @@ class MemoTest :
memo.toXdr().discriminant shouldBe MemoType.MEMO_ID
memo.toXdr().id.uint64.number shouldBe BigInteger.valueOf(9223372036854775807L)
memo.toString() shouldBe "9223372036854775807"
Memo.fromXdr(memo.toXdr()) shouldBe memo
}

test("should create id memo with 0") {
Expand All @@ -82,6 +91,7 @@ class MemoTest :
memo.toXdr().discriminant shouldBe MemoType.MEMO_ID
memo.toXdr().id.uint64.number shouldBe BigInteger.ZERO
memo.toString() shouldBe "0"
Memo.fromXdr(memo.toXdr()) shouldBe memo
}

test("should throw exception when id is negative") {
Expand All @@ -98,6 +108,7 @@ class MemoTest :
memo.bytes shouldBe bytes
memo.hexValue shouldBe "4141414141414141414141414141414141414141414141414141414141414141"
memo.toString() shouldBe "4141414141414141414141414141414141414141414141414141414141414141"
Memo.fromXdr(memo.toXdr()) shouldBe memo
}

test("should create hash memo from hex string") {
Expand All @@ -114,6 +125,7 @@ class MemoTest :
memo.toXdr().discriminant shouldBe MemoType.MEMO_HASH
memo.hexValue shouldBe hashHex.lowercase()
memo.toString() shouldBe hashHex.lowercase()
Memo.fromXdr(memo.toXdr()) shouldBe memo
}

test("should throw exception when bytes are not 32-bytes long") {
Expand Down Expand Up @@ -143,6 +155,7 @@ class MemoTest :
memo.bytes shouldBe bytes
memo.hexValue shouldBe "4141414141414141414141414141414141414141414141414141414141414141"
memo.toString() shouldBe "4141414141414141414141414141414141414141414141414141414141414141"
Memo.fromXdr(memo.toXdr()) shouldBe memo
}

test("should create return hash memo from hex string") {
Expand All @@ -151,6 +164,7 @@ class MemoTest :
memo.toXdr().discriminant shouldBe MemoType.MEMO_RETURN
memo.hexValue shouldBe hashHex.lowercase()
memo.toString() shouldBe hashHex.lowercase()
Memo.fromXdr(memo.toXdr()) shouldBe memo
}

test("should create return hash memo from uppercase hex string") {
Expand All @@ -159,6 +173,7 @@ class MemoTest :
memo.toXdr().discriminant shouldBe MemoType.MEMO_RETURN
memo.hexValue shouldBe hashHex.lowercase()
memo.toString() shouldBe hashHex.lowercase()
Memo.fromXdr(memo.toXdr()) shouldBe memo
}

test("should throw exception when bytes are not 32-bytes long") {
Expand Down
Loading