Skip to content

Commit

Permalink
Merge pull request #162 from wavesplatform/T412-allow-empty-strings-i…
Browse files Browse the repository at this point in the history
…n-assetid-attachment

T412 Allow empty strings in asset ids and attachments
  • Loading branch information
alexeykiselev authored Feb 22, 2017
2 parents d61f407 + fa8dd72 commit 1146150
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ case class SignedTransferRequest(@ApiModelProperty(value = "Base58 encoded sende
signature: String) extends BroadcastRequest {
def toTx: Either[ValidationError, TransferTransaction] = for {
_sender <- PublicKeyAccount.fromBase58String(senderPublicKey)
_assetId <- parseBase58ToOption(assetId, "invalid.assetId", AssetIdStringLength)
_feeAssetId <- parseBase58ToOption(feeAssetId, "invalid.feeAssetId", AssetIdStringLength)
_assetId <- parseBase58ToOption(assetId.filter(_.length > 0), "invalid.assetId", AssetIdStringLength)
_feeAssetId <- parseBase58ToOption(feeAssetId.filter(_.length > 0), "invalid.feeAssetId", AssetIdStringLength)
_signature <- parseBase58(signature, "invalid.signature", SignatureStringLength)
_attachment <- parseBase58(attachment, "invalid.attachment", TransferTransaction.MaxAttachmentStringSize)
_attachment <- parseBase58(attachment.filter(_.length > 0), "invalid.attachment", TransferTransaction.MaxAttachmentStringSize)
_account <- if (Account.isValidAddress(recipient)) Right(new Account(recipient)) else Left(InvalidAddress)
_t <- TransferTransaction.create(_assetId, _sender, _account, amount, timestamp, _feeAssetId, fee, _attachment,
_signature)
Expand Down
3 changes: 1 addition & 2 deletions src/test/scala/scorex/api/http/RequestGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ trait RequestGen extends TransactionGen {
.map(Base58.encode)

val addressGen: G[String] = listOfN(32, Arbitrary.arbByte.arbitrary).map(b => Base58.encode(b.toArray))
val fee: G[Long] = choose(0, Long.MaxValue)
val signatureGen: G[String] = listOfN(TypedTransaction.SignatureLength, Arbitrary.arbByte.arbitrary)
.map(b => Base58.encode(b.toArray))
private val assetIdStringGen = assetIdGen.map(_.map(Base58.encode))

private val commonFields = for {
_account <- addressGen
_fee <- fee
_fee <- smallFeeGen
} yield (_account, _fee)

val issueReq: G[IssueRequest] = for {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package scorex.api.http.assets

import com.typesafe.config.ConfigFactory
import com.wavesplatform.http.ApiMarshallers._
import akka.http.scaladsl.testkit._
import com.wavesplatform.settings.RestAPISettings
import org.scalacheck.Gen._
import org.scalacheck.{Gen => G}
Expand Down Expand Up @@ -83,6 +82,13 @@ class AssetsBroadcastRouteSpec extends RouteSpec("/assets/broadcast/") with Requ
"transfer transaction" in forAll(broadcastTransferReq) { tr =>
def posting[A: Writes](v: A) = Post(routePath("transfer"), v) ~> route

posting(tr.copy(attachment = Some(""))) should produce(InvalidSignature)
posting(tr.copy(attachment = None)) should produce(InvalidSignature)
posting(tr.copy(assetId = Some(""))) should produce(InvalidSignature)
posting(tr.copy(assetId = None)) should produce(InvalidSignature)
posting(tr.copy(feeAssetId = Some(""))) should produce(InvalidSignature)
posting(tr.copy(feeAssetId = None)) should produce(InvalidSignature)

forAll(nonPositiveLong) { q => posting(tr.copy(amount = q)) should produce (NegativeAmount) }
forAll(invalidBase58) { pk => posting(tr.copy(senderPublicKey = pk)) should produce (InvalidAddress) }
forAll(invalidBase58) { pk => posting(tr.copy(recipient = pk)) should produce (InvalidAddress) }
Expand Down

0 comments on commit 1146150

Please sign in to comment.