@@ -148,4 +148,64 @@ class ScriptApiRouteSpec extends AnyFlatSpec
148148 Get (s " $prefix/ $suffix/ $p2s" ) ~> route ~> check(assertion(responseAs[Json ], p2s))
149149 }
150150
151+ it should " generate addresses with different tree versions" in {
152+ val p2sSuffix = " /p2sAddress"
153+ val p2shSuffix = " /p2shAddress"
154+
155+ var p2sAddressV0 : String = " "
156+ var p2shAddressV0 : String = " "
157+ var p2sAddressV1 : String = " "
158+ var p2shAddressV1 : String = " "
159+
160+ // Test with tree version 0
161+ Post (prefix + p2sSuffix, Json .obj(" source" -> scriptSource.asJson, " treeVersion" -> 0 .asJson)) ~> route ~> check {
162+ status shouldBe StatusCodes .OK
163+ val addressStr = responseAs[Json ].hcursor.downField(" address" ).as[String ].right.get
164+ addressEncoder.fromString(addressStr).get.addressTypePrefix shouldEqual Pay2SAddress .addressTypePrefix
165+ p2sAddressV0 = addressStr
166+ }
167+
168+ Post (prefix + p2shSuffix, Json .obj(" source" -> scriptSource.asJson, " treeVersion" -> 0 .asJson)) ~> route ~> check {
169+ status shouldBe StatusCodes .OK
170+ val addressStr = responseAs[Json ].hcursor.downField(" address" ).as[String ].right.get
171+ addressEncoder.fromString(addressStr).get.addressTypePrefix shouldEqual Pay2SHAddress .addressTypePrefix
172+ p2shAddressV0 = addressStr
173+ }
174+
175+ // Test with tree version 1
176+ Post (prefix + p2sSuffix, Json .obj(" source" -> scriptSource.asJson, " treeVersion" -> 1 .asJson)) ~> route ~> check {
177+ status shouldBe StatusCodes .OK
178+ val addressStr = responseAs[Json ].hcursor.downField(" address" ).as[String ].right.get
179+ addressEncoder.fromString(addressStr).get.addressTypePrefix shouldEqual Pay2SAddress .addressTypePrefix
180+ p2sAddressV1 = addressStr
181+ }
182+
183+ Post (prefix + p2shSuffix, Json .obj(" source" -> scriptSource.asJson, " treeVersion" -> 1 .asJson)) ~> route ~> check {
184+ status shouldBe StatusCodes .OK
185+ val addressStr = responseAs[Json ].hcursor.downField(" address" ).as[String ].right.get
186+ addressEncoder.fromString(addressStr).get.addressTypePrefix shouldEqual Pay2SHAddress .addressTypePrefix
187+ p2shAddressV1 = addressStr
188+ }
189+
190+ // Get the actual Ergo trees and verify they have different version bytes
191+ val p2sTreeV0 = addressEncoder.fromString(p2sAddressV0).get.script
192+ val p2sTreeV1 = addressEncoder.fromString(p2sAddressV1).get.script
193+ val p2shTreeV0 = addressEncoder.fromString(p2shAddressV0).get.script
194+ val p2shTreeV1 = addressEncoder.fromString(p2shAddressV1).get.script
195+
196+ // Check that the trees have different version bytes
197+ p2sTreeV0.bytes should not equal p2sTreeV1.bytes
198+ p2shTreeV0.bytes shouldBe p2shTreeV1.bytes
199+
200+ // Specifically check the version byte (first byte of ErgoTree)
201+ p2sTreeV0.bytes.head should not equal p2sTreeV1.bytes.head
202+ p2shTreeV0.bytes.head shouldBe p2shTreeV1.bytes.head
203+
204+ // Verify the actual version bytes match what we requested
205+ p2sTreeV0.bytes.head shouldEqual 16
206+ p2sTreeV1.bytes.head shouldEqual 25
207+ p2shTreeV0.bytes.head shouldEqual 0
208+ p2shTreeV1.bytes.head shouldEqual 0
209+ }
210+
151211}
0 commit comments