Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STO invalidation test: actor has not enough TMSC to pay for fees #40

Merged
merged 3 commits into from
Jan 30, 2015
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
Expand Up @@ -44,7 +44,7 @@ class MSCSendToOwnersTestPlanSpec extends BaseRegTestSpec {
def startMSC = mscAvailable + mscReserved
def actorAddress = createFundedAddress(startBTC, startMSC)
def currencyMSC = new CurrencyID(ecosystem.longValue())
def currencySPT = createStoProperty(actorAddress, data)
def currencySPT = getStoProperty(actorAddress, data)

// Create a DEx offer to reserve an amount
if (mscReserved > 0) {
Expand Down Expand Up @@ -252,20 +252,30 @@ class MSCSendToOwnersTestPlanSpec extends BaseRegTestSpec {
}

/**
* Creates a new property and returns it's identifier.
* Parses the property identifier and creates a new property, if it's neither MSC or TMSC.
*/
def createStoProperty(Address actorAddress, def data) {
def getStoProperty(Address actorAddress, def data) {
def amountAvailableOwners = Eval.me(data.AmountAvailableOwners) as List<BigDecimal>
def amountAvailable = new BigDecimal(data.AmountAvailable)
def ecosystem = new Ecosystem(Short.valueOf(data.Ecosystem))
def propertyType = new PropertyType(Integer.valueOf(data.PropertyType))

def numberOfTokens = amountAvailable
def propertyName = new String(data.PropertyName)
def numberOfTokens = 0.0

if (amountAvailableOwners.size()) {
numberOfTokens += amountAvailableOwners.sum()
}

if (propertyName == "MSC" || propertyName == "TMSC") {
if (numberOfTokens > 0) {
requestMSC(actorAddress, numberOfTokens)
generateBlock()
}
return CurrencyID.valueOf(propertyName)
}

numberOfTokens += amountAvailable

if (propertyType == PropertyType.DIVISIBLE) {
numberOfTokens = BTC.btcToSatoshis(numberOfTokens)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Sender STO amount exceeds the number owned and available by the sending address,
Sender does not have a sufficient MSC available balance to pay the transfer fee, MSC reserved balance > 0 2 2 TDiv1 1.0 0.0 1.0 0.00000001 0.0 2 [1.0, 1.0] [0.0, 0.0] false false 1.0 0.0 0.00000001 0.0 [1.0, 1.0] [0.0, 0.0]
Sender MSC available balance = 0, MSC reserved balance > 0 2 2 TDiv1 1.0 0.0 0.1 0.0 0.1 2 [1.0, 1.0] [0.0, 0.0] false false 1.0 0.0 0.0 0.1 [1.0, 1.0] [0.0, 0.0]
Sender owns all the coins of the STO Property after issuance (tx50, tx55) but before any distributions/sends 2 2 TDiv1 1.0 0.0 0.1 1.0 0.0 0 [] [] false false 1.0 0.0 1.0 0.0 [] []
Sender does not have sufficient MSC for STO amount + transfer fee 2 2 TMSC 0.000001 0.0 0.000001 0.000001 0.0 1 [1.0] [0.0] false false 0.000001 0.0 0.000001 0.0 [1.0] [0.0]
One receiving owner (available balance > 0) 2 2 TDiv1 92233720368.54775806 0.0 0.00000001 0.1 0.0 1 [0.00000001] [0.0] false true 92233720368.54775805 0.0 0.09999999 0.0 [0.00000002] [0.0]
Two equal owners (available balance > 0, amount divisible by number of owners) 2 2 TDiv2 90000000000.0 0.0 10000000000.0 0.1 0.0 2 [1.0, 1.0] [0.0, 0.0] false true 80000000000.0 0.0 0.09999998 0.0 [5000000001.0, 5000000001.0] [0.0, 0.0]
Three equal owners (available balance > 0, amount divisible by number of owners) 2 2 TDiv2 80000000000.0 0.0 333.3 0.1 0.0 3 [1.0, 1.0, 1.0] [0.0, 0.0, 0.0] false true 79999999666.7 0.0 0.09999997 0.0 [112.1, 112.1, 112.1] [0.0, 0.0, 0.0]
Expand Down
14 changes: 13 additions & 1 deletion src/main/groovy/foundation/omni/test/TestSupport.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trait TestSupport implements MastercoinClientDelegate {
return accountName
}

def requestBitcoin(Address toAddress, BigDecimal requestedBTC) {
Sha256Hash requestBitcoin(Address toAddress, BigDecimal requestedBTC) {
def amountGatheredSoFar = 0.0
def inputs = new ArrayList<Map<String, Object>>()

Expand Down Expand Up @@ -68,6 +68,18 @@ trait TestSupport implements MastercoinClientDelegate {
return txid
}

Sha256Hash requestMSC(Address toAddress, BigDecimal requestedMSC) {
final MPNetworkParameters params = MPRegTestParams.get() // Hardcoded for RegTest for now

// TODO: avoid inaccurate funding
// TODO: integrate into createFundedAddress
def btcForMSC = (requestedMSC / 100).setScale(8, BigDecimal.ROUND_UP)
requestBitcoin(toAddress, btcForMSC + stdTxFee)

def txid = sendBitcoin(toAddress, params.moneyManAddress, btcForMSC)
return txid
}

Address createFundedAddress(BigDecimal requestedBTC, BigDecimal requestedMSC) {
final MPNetworkParameters params = MPRegTestParams.get() // Hardcoded for RegTest for now
Address stepAddress = getNewAddress()
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/foundation/omni/CurrencyID.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ public final class CurrencyID extends Number implements Cloneable {
public static final CurrencyID MaidSafeCoin = new CurrencyID(MaidSafeCoin_VALUE);
public static final CurrencyID TetherUS = new CurrencyID(TetherUS_VALUE);

public static CurrencyID valueOf(String s) {
switch (s) {
case "BTC":
return BTC;
case "MSC":
return MSC;
case "TMSC":
return TMSC;
case "MaidSafeCoin":
return MaidSafeCoin;
case "TetherUS":
return TetherUS;
}
throw new NumberFormatException();
}

public CurrencyID(long value) {
if (value < MIN_VALUE) {
throw new NumberFormatException();
Expand Down
17 changes: 17 additions & 0 deletions src/test/groovy/foundation/omni/CurrencyIDSpec.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package foundation.omni

import spock.lang.Specification
import spock.lang.Unroll

/**
* User: sean
Expand Down Expand Up @@ -152,4 +153,20 @@ class CurrencyIDSpec extends Specification {
4294967295 | "CurrencyID:4294967295"
}

@Unroll
def "The String \"#str\" can be used to create CurrencyID:#value"() {

expect:
CurrencyID currency = CurrencyID.valueOf(str)
currency.longValue() == value

where:
str | value
"BTC" | CurrencyID.BTC_VALUE
"MSC" | CurrencyID.MSC_VALUE
"TMSC" | CurrencyID.TMSC_VALUE
"MaidSafeCoin" | CurrencyID.MaidSafeCoin_VALUE
"TetherUS" | CurrencyID.TetherUS_VALUE
}

}