Skip to content

Commit

Permalink
Deprecate OmniExtendedClient
Browse files Browse the repository at this point in the history
* Deprecate OmniExtendedClient and all its methods
* Create OmniTestClient to replace OmniExtendedClient in integration tests
* Create OmniTestClientDelegate trait for use in tests
* OmniCLIClient now extends OmniClient rather than OmniExtendedClient
* Don’t use OmniCLIClient in most tests (use OmniTestClient instead)
* OmniClientDelegate uses OmniClient (not OmniCLIClient)
* OmniScriptingClient uses OmniClient (not OmniExtendedClient)
* Fix issue with omni_senddexsell sending real number not string
   (note this is different from how BTC values are sent in standard Bitcoin RPCs)
  • Loading branch information
msgilligan committed Nov 16, 2016
1 parent 03e447e commit 628faab
Show file tree
Hide file tree
Showing 15 changed files with 370 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ConsensusCLISpec extends Specification implements CLITestSupport {
result.error.length() == 0
}

def "fetch MSC consensus to stdout"() {
def "fetch Omni consensus to stdout"() {
when:
def result = command "-regtest -rpcuser=${rpcUser} -rpcpassword=${rpcPassword} -rpcwait -property 1"

Expand All @@ -42,7 +42,7 @@ class ConsensusCLISpec extends Specification implements CLITestSupport {
result.error.length() == 0
}

def "fetch MSC consensus to stdout with rpcconnect option"() {
def "fetch Omni consensus to stdout with rpcconnect option"() {
when:
def result = command "-regtest -rpcuser=${rpcUser} -rpcpassword=${rpcPassword} -rpcwait -property=1 -rpcconnect=127.0.0.1"

Expand All @@ -53,7 +53,7 @@ class ConsensusCLISpec extends Specification implements CLITestSupport {
}


def "fetch MSC consensus to stdout setting bad username & password"() {
def "fetch Omni consensus to stdout setting bad username & password"() {
when:
def result = command '-regtest -rpcwait -rpcuser=x -rpcpassword=y -property=1'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package foundation.omni

import com.msgilligan.bitcoinj.json.pojo.NetworkInfo
import com.msgilligan.bitcoinj.rpc.Loggable
import com.msgilligan.bitcoinj.rpc.RPCURI
import com.msgilligan.bitcoinj.test.RegTestFundingSource
import foundation.omni.rpc.OmniCLIClient
import foundation.omni.rpc.OmniClientDelegate
import foundation.omni.rpc.test.OmniTestClient
import foundation.omni.rpc.test.TestServers
import foundation.omni.test.OmniTestClientDelegate
import foundation.omni.test.OmniTestSupport
import org.bitcoinj.core.NetworkParameters
import org.bitcoinj.params.RegTestParams
Expand All @@ -15,14 +18,14 @@ import spock.lang.Specification
/**
* Base specification for integration tests on RegTest net
*/
abstract class BaseRegTestSpec extends Specification implements OmniClientDelegate, OmniTestSupport, Loggable {
abstract class BaseRegTestSpec extends Specification implements OmniTestClientDelegate, OmniTestSupport, Loggable {

static final private TestServers testServers = TestServers.instance
static final protected String rpcTestUser = testServers.rpcTestUser
static final protected String rpcTestPassword = testServers.rpcTestPassword;

{
client = new OmniCLIClient(RegTestParams.get(), RPCURI.defaultRegTestURI, rpcTestUser, rpcTestPassword)
client = new OmniTestClient(RegTestParams.get(), RPCURI.defaultRegTestURI, rpcTestUser, rpcTestPassword)
fundingSource = new RegTestFundingSource(client)
}

Expand All @@ -35,9 +38,10 @@ abstract class BaseRegTestSpec extends Specification implements OmniClientDelega

// Set and confirm default fees, so a known reference value can be used in tests
assert client.setTxFee(stdTxFee)
def basicinfo = client.getinfo()
assert basicinfo.paytxfee == stdTxFee
assert basicinfo.relayfee == stdRelayTxFee
NetworkInfo basicinfo = client.getNetworkInfo()
// TODO: How to update the following 2 asserts given that getinfo is deprecated
//assert basicinfo.paytxfee == stdTxFee
//assert basicinfo.relayFee == stdRelayTxFee.value
}

void cleanupSpec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SendRawTransactionSpec extends BaseRegTestSpec {

def setup() {
activeAddress = createFundedAddress(startBTC, startMSC)
passiveAddress = getnewaddress()
passiveAddress = getNewAddress()
}

def "Create raw transaction with reference address"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import foundation.omni.OmniDivisibleValue
import org.bitcoinj.core.Coin
import spock.lang.Unroll

import static CurrencyID.OMNI
import static CurrencyID.TOMNI
import static foundation.omni.CurrencyID.OMNI
import static foundation.omni.CurrencyID.TOMNI

/**
* Specification for the traditional distributed exchange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class SendToOwnersTestPlanSpec extends BaseRegTestSpec {
Coin commitFee = 0.0001.btc
Byte action = 1 // new offer

def txid = createDexSellOffer(actorAddress, currency, amount, desiredBTC, blockSpan, commitFee, action)
def txid = omniSendDExSell(actorAddress, currency, amount, desiredBTC, blockSpan, commitFee, action)
generateBlock()

def transaction = omniGetTransaction(txid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import groovy.transform.CompileStatic
*
*/
@CompileStatic
class OmniCLIClient extends OmniExtendedClient {
class OmniCLIClient extends OmniClient {

OmniCLIClient(NetworkParameters netParams, URI server, String rpcuser, String rpcpassword) {
super(netParams, server, rpcuser, rpcpassword)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package foundation.omni.rpc

/**
* Groovy trait for adding a OmniCLIClient delegate to any class
* Groovy trait for adding a OmniClient delegate to any class
*/
trait OmniClientDelegate {
@Delegate
OmniCLIClient client
OmniClient client
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.io.IOException;
* No args constructor reads bitcoin.conf
* Allows dynamic methods to access new RPCs
*/
public class OmniScriptingClient extends OmniExtendedClient implements DynamicRPCFallback {
public class OmniScriptingClient extends OmniClient implements DynamicRPCFallback {

public OmniScriptingClient() {
super(BitcoinConfFile.readDefaultConfig().getRPCConfig());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package foundation.omni.test

import foundation.omni.rpc.OmniCLIClient
import foundation.omni.rpc.test.OmniTestClient

/**
* Groovy trait for adding an OmniTestClient delegate to any class
*/
trait OmniTestClientDelegate {
@Delegate
OmniTestClient client
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import foundation.omni.rpc.OmniClientDelegate
/**
* Test support functions intended to be mixed-in to Spock test specs
*/
trait OmniTestSupport implements BTCTestSupport, OmniClientDelegate, RawTxDelegate {
trait OmniTestSupport implements BTCTestSupport, OmniTestClientDelegate, RawTxDelegate {

Sha256Hash requestMSC(Address toAddress, OmniDivisibleValue requestedOmni) {
return requestMSC(toAddress, requestedOmni, true)
Expand Down Expand Up @@ -91,7 +91,7 @@ trait OmniTestSupport implements BTCTestSupport, OmniClientDelegate, RawTxDelega
def fundedAddress = newAddress

if (requestedMSC.willets > 0) {
def txidMSC = requestMSC(fundedAddress, requestedMSC)
def txidMSC = requestMSC(fundedAddress, (OmniDivisibleValue) requestedMSC)
}

if (requestedBTC.value > 0) {
Expand Down Expand Up @@ -119,7 +119,17 @@ trait OmniTestSupport implements BTCTestSupport, OmniClientDelegate, RawTxDelega
}

CurrencyID fundNewProperty(Address address, OmniValue amount, Ecosystem ecosystem) {
def txidCreation = createProperty(address, ecosystem, amount)
def txidCreation = omniSendIssuanceFixed(address,
ecosystem,
amount.getPropertyType(),
new CurrencyID(0), // previousId
"", // category
"", // subCategory
"name", // name
"", // url
"", // data
amount);

generateBlock()
def txCreation = omniGetTransaction(txidCreation)
assert txCreation.valid == true
Expand All @@ -128,7 +138,15 @@ trait OmniTestSupport implements BTCTestSupport, OmniClientDelegate, RawTxDelega
}

CurrencyID fundManagedProperty(Address address, PropertyType type, Ecosystem ecosystem) {
def txidCreation = createManagedProperty(address, ecosystem, type, "", "", "MSP", "", "")
def txidCreation = omniSendIssuanceManaged(address,
ecosystem,
type,
new CurrencyID(0), // previousId
"", // category
"", // subCategory
"MSP",
"", // url
"") // data
generateBlock()
def txCreation = omniGetTransaction(txidCreation)
assert txCreation.valid == true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package foundation.omni.test

import com.msgilligan.bitcoinj.rpc.RPCURI
import com.msgilligan.bitcoinj.test.RegTestEnvironment
import foundation.omni.rpc.OmniCLIClient
import foundation.omni.rpc.test.OmniTestClient
import org.bitcoinj.params.RegTestParams

/**
*
*/
class RegTestContext {
static setup(String user, String pass) {
def client = new OmniCLIClient(RegTestParams.get(), RPCURI.defaultRegTestURI, user, pass)
def client = new OmniTestClient(RegTestParams.get(), RPCURI.defaultRegTestURI, user, pass)
def env = new RegTestEnvironment(client)
def funder = new RegTestOmniFundingSource(client)
return [client, env, funder]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package foundation.omni.test;

import com.msgilligan.bitcoinj.test.RegTestFundingSource;
import foundation.omni.rpc.OmniCLIClient;
import foundation.omni.rpc.test.OmniTestClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -12,8 +12,8 @@ import org.slf4j.LoggerFactory;
public class RegTestOmniFundingSource extends RegTestFundingSource implements OmniTestSupport, OmniFundingSource {
private static final Logger log = LoggerFactory.getLogger(RegTestFundingSource.class);

public RegTestOmniFundingSource(OmniCLIClient client) {
public RegTestOmniFundingSource(OmniTestClient client) {
super(client); // Set BitcoinExtendedClient in superclass
foundation_omni_rpc_OmniClientDelegate__client = client; // Set Omni client here
foundation_omni_test_OmniTestClientDelegate__client = client; // Set Omni client here
}
}
9 changes: 7 additions & 2 deletions omnij-rpc/src/main/java/foundation/omni/rpc/OmniClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,13 @@ public Sha256Hash omniSendDExSell(Address fromAddress, CurrencyID currencyId, Om
Coin amountDesired, Byte paymentWindow, Coin commitmentFee,
Byte action)
throws JsonRPCException, IOException {
return send("omni_senddexsell", Sha256Hash.class, fromAddress, currencyId, amountForSale, amountDesired,
paymentWindow, commitmentFee, action);
return send("omni_senddexsell", Sha256Hash.class,
fromAddress, currencyId,
amountForSale,
amountDesired.toString(), // Omni Core expects string for BTC value, unlike BTC RPCs?
paymentWindow,
commitmentFee.toString(),
action);
}

/**
Expand Down
Loading

0 comments on commit 628faab

Please sign in to comment.