From ad25c77988346b6c1863d81e2fe4b78701cd85e0 Mon Sep 17 00:00:00 2001 From: dexX7 Date: Wed, 28 Jan 2015 06:38:27 +0100 Subject: [PATCH] 4 crowdsale tests of conversion rate See: https://github.com/mastercoin-MSC/mastercore/issues/234#issuecomment-71783278 --- .../omni/test/rpc/misc/CrowdsaleSpec.groovy | 201 ++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 src/integ/groovy/foundation/omni/test/rpc/misc/CrowdsaleSpec.groovy diff --git a/src/integ/groovy/foundation/omni/test/rpc/misc/CrowdsaleSpec.groovy b/src/integ/groovy/foundation/omni/test/rpc/misc/CrowdsaleSpec.groovy new file mode 100644 index 00000000..ddfb1195 --- /dev/null +++ b/src/integ/groovy/foundation/omni/test/rpc/misc/CrowdsaleSpec.groovy @@ -0,0 +1,201 @@ +package foundation.omni.test.rpc.misc + +import foundation.omni.BaseRegTestSpec +import foundation.omni.CurrencyID + +class CrowdsaleSpec extends BaseRegTestSpec { + + final static BigDecimal startBTC = 0.1 + final static BigDecimal startMSC = 100.0 + + def "Crowdsale with 0.00000001 DivSPT for 0.00000001 MSC, invest 0.00000001 MSC"() { + /* + { + "version" : 0, + "type" : 51, + "ecosystem" : 1, + "property_type" : 2, + "previous_property_id" : 0, + "category" : "", + "subcategory" : "", + "name" : "MDiv", + "url" : "", + "data" : "", + "property_desired" : 1, + "token_per_unit_vested" : 1, + "deadline" : 7731414000, + "issuer_bonus" : 0 + } + */ + def rawTx = "000000330100020000000000004d44697600000000000001000000000000000100000001ccd403f00000" + def issuerAddress = createFundedAddress(startBTC, startMSC) + def investorAddress = createFundedAddress(startBTC, startMSC) + def currencyMSC = CurrencyID.MSC + + when: "creating a new crowdsale with 0.00000001 DivisibleSPT for 0.00000001 MSC" + def crowdsaleTxid = sendrawtx_MP(issuerAddress, rawTx) + generateBlock() + + then: "the crowdsale is active" + def crowdsaleTx = getTransactionMP(crowdsaleTxid) + crowdsaleTx.confirmations == 1 + crowdsaleTx.valid == true + def propertyId = new CurrencyID(crowdsaleTx.propertyid as Long) + def crowdsaleInfo = getCrowdsale(propertyId) + crowdsaleInfo.active == true + + when: "participant invests 0.00000001 MSC" + def sendTxid = send_MP(investorAddress, issuerAddress, currencyMSC, 0.00000001) + generateBlock() + + then: "the investor should get 0.00000001 token" + def sendTx = getTransactionMP(sendTxid) + sendTx.valid == true + getbalance_MP(investorAddress, propertyId).balance == 0.00000001 + } + + def "Crowdsale with 0.00000001 DivSPT for 0.00000001 MSC, invest 1.00000000 MSC"() { + /* + { + "version" : 0, + "type" : 51, + "ecosystem" : 1, + "property_type" : 2, + "previous_property_id" : 0, + "category" : "", + "subcategory" : "", + "name" : "MDiv", + "url" : "", + "data" : "", + "property_desired" : 1, + "token_per_unit_vested" : 1, + "deadline" : 7731414000, + "issuer_bonus" : 0 + } + */ + def rawTx = "000000330100020000000000004d44697600000000000001000000000000000100000001ccd403f00000" + def issuerAddress = createFundedAddress(startBTC, startMSC) + def investorAddress = createFundedAddress(startBTC, startMSC) + def currencyMSC = CurrencyID.MSC + + when: "creating a new crowdsale with 0.00000001 DivisibleSPT for 0.00000001 MSC" + def crowdsaleTxid = sendrawtx_MP(issuerAddress, rawTx) + generateBlock() + + then: "the crowdsale is active" + def crowdsaleTx = getTransactionMP(crowdsaleTxid) + crowdsaleTx.confirmations == 1 + crowdsaleTx.valid == true + def propertyId = new CurrencyID(crowdsaleTx.propertyid as Long) + def crowdsaleInfo = getCrowdsale(propertyId) + crowdsaleInfo.active == true + + when: "participant invests 1.00000000 MSC" + def sendTxid = send_MP(investorAddress, issuerAddress, currencyMSC, 1.00000000) + generateBlock() + + then: "the investor should get 1.00000000 token" + def sendTx = getTransactionMP(sendTxid) + sendTx.valid == true + getbalance_MP(investorAddress, propertyId).balance == 1.00000000 + } + + def "Crowdsale with 1 IndivSPT for 0.00000001 MSC, invest 0.00000001 MSC"() { + /* + { + "version" : 0, + "type" : 51, + "ecosystem" : 1, + "property_type" : 1, + "previous_property_id" : 0, + "category" : "", + "subcategory" : "", + "name" : "MIndiv", + "url" : "", + "data" : "", + "property_desired" : 1, + "token_per_unit_vested" : 1, + "deadline" : 7731414000, + "issuer_bonus" : 0 + } + */ + def rawTx = "000000330100010000000000004d496e64697600000000000001000000000000000100000001ccd403f00000" + def issuerAddress = createFundedAddress(startBTC, startMSC) + def investorAddress = createFundedAddress(startBTC, startMSC) + def currencyMSC = CurrencyID.MSC + + when: "creating a new crowdsale with 1 IndivisibleSPT for 0.00000001 MSC" + def crowdsaleTxid = sendrawtx_MP(issuerAddress, rawTx) + generateBlock() + + then: "the crowdsale is active" + def crowdsaleTx = getTransactionMP(crowdsaleTxid) + crowdsaleTx.confirmations == 1 + crowdsaleTx.valid == true + def propertyId = new CurrencyID(crowdsaleTx.propertyid as Long) + def crowdsaleInfo = getCrowdsale(propertyId) + crowdsaleInfo.active == true + + when: "participant invests 0.00000001 MSC" + def sendTxid = send_MP(investorAddress, issuerAddress, currencyMSC, 0.00000001) + generateBlock() + + then: "the investor should get 1 token" + def sendTx = getTransactionMP(sendTxid) + sendTx.valid == true + getbalance_MP(investorAddress, propertyId).balance == 1 + } + + def "Crowdsale with 1 IndivSPT for 0.00000001 MSC, invest 1.00000000 MSC"() { + /* + { + "version" : 0, + "type" : 51, + "ecosystem" : 1, + "property_type" : 1, + "previous_property_id" : 0, + "category" : "", + "subcategory" : "", + "name" : "MIndiv", + "url" : "", + "data" : "", + "property_desired" : 1, + "token_per_unit_vested" : 1, + "deadline" : 7731414000, + "issuer_bonus" : 0 + } + */ + def rawTx = "000000330100010000000000004d496e64697600000000000001000000000000000100000001ccd403f00000" + def issuerAddress = createFundedAddress(startBTC, startMSC) + def investorAddress = createFundedAddress(startBTC, startMSC) + def currencyMSC = CurrencyID.MSC + + when: "creating a new crowdsale with 1 IndivisibleSPT for 0.00000001 MSC" + def crowdsaleTxid = sendrawtx_MP(issuerAddress, rawTx) + generateBlock() + + then: "the crowdsale is active" + def crowdsaleTx = getTransactionMP(crowdsaleTxid) + crowdsaleTx.confirmations == 1 + crowdsaleTx.valid == true + def propertyId = new CurrencyID(crowdsaleTx.propertyid as Long) + def crowdsaleInfo = getCrowdsale(propertyId) + crowdsaleInfo.active == true + + when: "participant invests 1.00000000 MSC" + def sendTxid = send_MP(investorAddress, issuerAddress, currencyMSC, 1.00000000) + generateBlock() + + then: "the investor should get 100000000 token" + def sendTx = getTransactionMP(sendTxid) + sendTx.valid == true + getbalance_MP(investorAddress, propertyId).balance == 100000000 + } + + def getCrowdsale(CurrencyID propertyId) { + def crowdsaleInfoResponse = client.send("getcrowdsale_MP", [propertyId.longValue()]) + def crowdsaleInfo = crowdsaleInfoResponse.result as Map + return crowdsaleInfo + } + +}