Skip to content

Commit

Permalink
Merge pull request tronprotocol#3417 from tronprotocol/hotfix/dex_pro…
Browse files Browse the repository at this point in the history
…tocol

rm useless parameter from protocol
  • Loading branch information
lvs007 authored Sep 29, 2020
2 parents 67d7e3e + 80553b4 commit f287cc6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,6 @@ private Any getContract(String address, String sellTokenId, long sellTokenQuanti
.build());
}

private Any getContract(String address, String sellTokenId, long sellTokenQuantity,
String buyTokenId, long buyTokenQuantity, ByteString prePriceKey) {

return Any.pack(
MarketSellAssetContract.newBuilder()
.setOwnerAddress(ByteString.copyFrom(ByteArray.fromHexString(address)))
.setSellTokenId(ByteString.copyFrom(sellTokenId.getBytes()))
.setSellTokenQuantity(sellTokenQuantity)
.setBuyTokenId(ByteString.copyFrom(buyTokenId.getBytes()))
.setBuyTokenQuantity(buyTokenQuantity)
.setPrePriceKey(prePriceKey)
.build());
}

//test case
//
// validate:
Expand Down Expand Up @@ -623,107 +609,9 @@ private void prepareAccount(String sellTokenId, String buyTokenId,
Assert.assertEquals(sellTokenQuant, (long) accountCapsule.getAssetMapV2().get(sellTokenId));
}

/**
* price exist
*/
@Test
public void validateSuccessWithPositionPriceExist() throws Exception {

InitAsset();

//(sell id_1 and buy id_2)
// TOKEN_ID_ONE has the same value as TOKEN_ID_ONE
String sellTokenId = TOKEN_ID_ONE;
long sellTokenQuant = 100L;
String buyTokenId = TOKEN_ID_TWO;
long buyTokenQuant = 219L;
byte[] ownerAddress = ByteArray.fromHexString(OWNER_ADDRESS_FIRST);

prepareAccount(sellTokenId, buyTokenId, sellTokenQuant, buyTokenQuant, ownerAddress);

//MAX_SEARCH_NUM = 10
for (int i = 0; i < 20; i++) {
byte[] prePriceKey = null;
if (i != 0) {
prePriceKey = MarketUtils
.createPairPriceKey(TOKEN_ID_ONE.getBytes(), TOKEN_ID_TWO.getBytes(), 100L,
200L + i - 1);
}

addOrder(TOKEN_ID_ONE, 100L, TOKEN_ID_TWO,
200L + i, OWNER_ADDRESS_FIRST, prePriceKey);
}

byte[] prePriceKey = MarketUtils
.createPairPriceKey(TOKEN_ID_ONE.getBytes(), TOKEN_ID_TWO.getBytes(), 100L, 200L);

// do process
MarketSellAssetActuator actuator = new MarketSellAssetActuator();
actuator.setChainBaseManager(dbManager.getChainBaseManager()).setAny(getContract(
OWNER_ADDRESS_FIRST, sellTokenId, sellTokenQuant, buyTokenId, buyTokenQuant,
ByteString.copyFrom(prePriceKey)));

try {
actuator.validate();
} catch (ContractValidateException e) {
fail("validateSuccess error");
}
}

/**
* validate Success with position, result is Success .
*/
@Test
public void validateSuccessWithPositionLimitCount() throws Exception {

InitAsset();

//(sell id_1 and buy id_2)
// TOKEN_ID_ONE has the same value as TOKEN_ID_ONE
String sellTokenId = TOKEN_ID_ONE;
long sellTokenQuant = 100L;
String buyTokenId = TOKEN_ID_TWO;
long buyTokenQuant = 300L;
byte[] ownerAddress = ByteArray.fromHexString(OWNER_ADDRESS_FIRST);

prepareAccount(sellTokenId, buyTokenId, sellTokenQuant, buyTokenQuant, ownerAddress);

//MAX_SEARCH_NUM = 10
for (int i = 0; i < 20; i++) {
byte[] prePriceKey = null;
if (i != 0) {
prePriceKey = MarketUtils
.createPairPriceKey(TOKEN_ID_ONE.getBytes(), TOKEN_ID_TWO.getBytes(), 100L,
200L + i - 1);
}

addOrder(TOKEN_ID_ONE, 100L, TOKEN_ID_TWO,
200L + i, OWNER_ADDRESS_FIRST, prePriceKey);
}

byte[] prePriceKey = MarketUtils
.createPairPriceKey(TOKEN_ID_ONE.getBytes(), TOKEN_ID_TWO.getBytes(), 100L, 210L);

// do process
MarketSellAssetActuator actuator = new MarketSellAssetActuator();
actuator.setChainBaseManager(dbManager.getChainBaseManager()).setAny(getContract(
OWNER_ADDRESS_FIRST, sellTokenId, sellTokenQuant, buyTokenId, buyTokenQuant,
ByteString.copyFrom(prePriceKey)));

try {
actuator.validate();
} catch (ContractValidateException e) {
fail("validateSuccess error");
}
}

private void addOrder(String sellTokenId, long sellTokenQuant,
String buyTokenId, long buyTokenQuant, String ownAddress) throws Exception {
addOrder(sellTokenId, sellTokenQuant, buyTokenId, buyTokenQuant, ownAddress, null);
}

private void addOrder(String sellTokenId, long sellTokenQuant,
String buyTokenId, long buyTokenQuant, String ownAddress, byte[] prePreKey) throws Exception {

byte[] ownerAddress = ByteArray.fromHexString(ownAddress);
AccountCapsule accountCapsule = dbManager.getAccountStore().get(ownerAddress);
Expand All @@ -733,14 +621,8 @@ private void addOrder(String sellTokenId, long sellTokenQuant,

// do process
MarketSellAssetActuator actuator = new MarketSellAssetActuator();
if (prePreKey == null || prePreKey.length == 0) {
actuator.setChainBaseManager(dbManager.getChainBaseManager()).setAny(getContract(
ownAddress, sellTokenId, sellTokenQuant, buyTokenId, buyTokenQuant));
} else {
actuator.setChainBaseManager(dbManager.getChainBaseManager()).setAny(getContract(
ownAddress, sellTokenId, sellTokenQuant, buyTokenId, buyTokenQuant,
ByteString.copyFrom(prePreKey)));
}
actuator.setChainBaseManager(dbManager.getChainBaseManager()).setAny(getContract(
ownAddress, sellTokenId, sellTokenQuant, buyTokenId, buyTokenQuant));

TransactionResultCapsule ret = new TransactionResultCapsule();
actuator.validate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ message MarketSellAssetContract {
int64 sell_token_quantity = 3;
bytes buy_token_id = 4;
int64 buy_token_quantity = 5; // min to receive
bytes pre_price_key = 6; // order price position
}

message MarketCancelOrderContract {
Expand Down

0 comments on commit f287cc6

Please sign in to comment.