Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package foundation.omni.test.rpc.sendall

import foundation.omni.BaseRegTestSpec
import foundation.omni.CurrencyID
import foundation.omni.Ecosystem
import foundation.omni.PropertyType
import org.junit.internal.AssumptionViolatedException

class SendAllSpec extends BaseRegTestSpec {

final static BigDecimal startBTC = 0.1
final static BigDecimal startMSC = 0.1
final static BigDecimal zeroAmount = 0.0

def "All available tokens can be transferred with transaction type 4"() {
when:
def actorAddress = createFundedAddress(startBTC, startMSC)
def otherAddress = newAddress

then:
getbalance_MP(actorAddress, CurrencyID.MSC).balance == startMSC
getbalance_MP(actorAddress, CurrencyID.TMSC).balance == startMSC
getbalance_MP(otherAddress, CurrencyID.MSC).balance == zeroAmount
getbalance_MP(otherAddress, CurrencyID.TMSC).balance == zeroAmount

when:
def sendTxid = sendAll(actorAddress, otherAddress)
generateBlock()
def sendTx = getTransactionMP(sendTxid)

then: "the transaction is valid"
sendTx.valid

and: "it has the specified values"
sendTx.txid == sendTxid.toString()
sendTx.sendingaddress == actorAddress.toString()
sendTx.referenceaddress == otherAddress.toString()
sendTx.type_int == 4
sendTx.containsKey('subsends')

and:
List<Map<String, Object>> subSends = sendTx['subsends']
subSends.size() == 2
for (def send : subSends) {
assert send.divisible
assert send.amount as BigDecimal == startMSC
}

and:
getbalance_MP(actorAddress, CurrencyID.MSC).balance == zeroAmount
getbalance_MP(actorAddress, CurrencyID.TMSC).balance == zeroAmount
getbalance_MP(otherAddress, CurrencyID.MSC).balance == startMSC
getbalance_MP(otherAddress, CurrencyID.TMSC).balance == startMSC
}

def "\"Send All\" transactions are only valid, if at least one token was transferred"() {
when:
def actorAddress = createFundedAddress(startBTC, startMSC)
def otherAddress = newAddress
send_MP(actorAddress, otherAddress, CurrencyID.MSC, startMSC)
send_MP(actorAddress, otherAddress, CurrencyID.TMSC, startMSC)
generateBlock()

then:
getbalance_MP(actorAddress, CurrencyID.MSC).balance == zeroAmount
getbalance_MP(actorAddress, CurrencyID.TMSC).balance == zeroAmount
getbalance_MP(otherAddress, CurrencyID.MSC).balance == startMSC
getbalance_MP(otherAddress, CurrencyID.TMSC).balance == startMSC

when:
def sendTxid = sendAll(actorAddress, otherAddress)
generateBlock()

then:
getTransactionMP(sendTxid).valid == false

and:
getbalance_MP(actorAddress, CurrencyID.MSC).balance == zeroAmount
getbalance_MP(actorAddress, CurrencyID.TMSC).balance == zeroAmount
getbalance_MP(otherAddress, CurrencyID.MSC).balance == startMSC
getbalance_MP(otherAddress, CurrencyID.TMSC).balance == startMSC
}

def "Only available, unreserved balances are transferred with \"Send All\""() {
when:
def actorAddress = createFundedAddress(startBTC, zeroAmount)
def otherAddress = createFundedAddress(startBTC, zeroAmount)
def nonManagedID = fundNewProperty(actorAddress, 10.0, PropertyType.DIVISIBLE, Ecosystem.MSC)

then:
getbalance_MP(actorAddress, nonManagedID).balance == 10.0
getbalance_MP(otherAddress, nonManagedID).balance == zeroAmount

when:
def tradeTxid = trade_MP(actorAddress, nonManagedID, 4.0, CurrencyID.MSC, 4.0, 1 as Byte)
generateBlock()
def tradeTx = getTransactionMP(tradeTxid)

then:
tradeTx.valid
getbalance_MP(actorAddress, nonManagedID).balance == 6.0
getbalance_MP(actorAddress, nonManagedID).reserved == 4.0

when:
def sendTxid = sendAll(actorAddress, otherAddress)
generateBlock()
def sendTx = getTransactionMP(sendTxid)

then:
sendTx.valid
getbalance_MP(actorAddress, nonManagedID).balance == zeroAmount
getbalance_MP(actorAddress, nonManagedID).reserved == 4.0
getbalance_MP(otherAddress, nonManagedID).balance == 6.0
}

def setupSpec() {
if (!commandExists("omni_sendall")) {
throw new AssumptionViolatedException('The client has no "omni_sendall" command')
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class ManagedPropertySpec extends BaseRegTestSpec {
getbalance_MP(actorAddress, currencyID).balance == new BigDecimal("9223372036854775807")
}

@Ignore
def "Granting more than 9223372036854775807 tokens in total is invalid"() {
when:
def txid = grantTokens(actorAddress, currencyID, 1)
Expand Down Expand Up @@ -219,7 +218,6 @@ class ManagedPropertySpec extends BaseRegTestSpec {
getbalance_MP(otherAddress, currencyID).balance == new BigDecimal("1")
}

@Ignore
def "Sending of granted tokens does not remove the limit of total tokens"() {
when:
def txid = grantTokens(actorAddress, currencyID, 1) // MAX < total + 1 (!)
Expand Down
15 changes: 15 additions & 0 deletions omnij-rpc/src/main/java/foundation/omni/rpc/OmniClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,21 @@ public Sha256Hash sendToOwnersMP(Address fromAddress, CurrencyID currency, BigDe
return hash;
}

/**
* Creates and broadcasts a "send all" transaction.
*
* @param fromAddress The address to spent from
* @param toAddress The address to send to
* @return The hash of the transaction
*/
public Sha256Hash sendAll(Address fromAddress, Address toAddress)
throws JsonRPCException, IOException {
List<Object> params = createParamList(fromAddress.toString(), toAddress.toString());
String txid = send("omni_sendall", params);
Sha256Hash hash = Sha256Hash.wrap(txid);
return hash;
}

/**
* Creates and broadcasts a "trade" transaction.
*
Expand Down