Skip to content

Commit

Permalink
Merge pull request tronprotocol#3607 from tronprotocol/test/4.1.2_case
Browse files Browse the repository at this point in the history
Test/4.1.2 case
  • Loading branch information
MiraculousWang authored Jan 6, 2021
2 parents 263892c + 024bbb3 commit 395582f
Show file tree
Hide file tree
Showing 18 changed files with 378 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.tron.api.GrpcAPI.TransactionExtention;
import org.tron.api.GrpcAPI.TransactionSignWeight;
import org.tron.api.WalletGrpc;
import org.tron.api.WalletGrpc.WalletBlockingStub;
import org.tron.api.WalletSolidityGrpc;
import org.tron.common.crypto.ECKey;
import org.tron.common.crypto.ECKey.ECDSASignature;
Expand Down Expand Up @@ -74,6 +75,7 @@
import org.tron.protos.contract.ExchangeContract.ExchangeInjectContract;
import org.tron.protos.contract.ExchangeContract.ExchangeTransactionContract;
import org.tron.protos.contract.ExchangeContract.ExchangeWithdrawContract;
import org.tron.protos.contract.MarketContract;
import org.tron.protos.contract.ProposalContract.ProposalApproveContract;
import org.tron.protos.contract.ProposalContract.ProposalCreateContract;
import org.tron.protos.contract.ProposalContract.ProposalDeleteContract;
Expand Down Expand Up @@ -5239,4 +5241,95 @@ public static boolean updateBrokerage(byte[] owner, int brokerage, String priKey

return broadcastTransaction(transaction, blockingStubFull);
}

/**
* constructor.
*/
public static boolean marketSellAsset(byte[] owner, byte[] sellTokenId,
long sellTokenQuantity, byte[] buyTokenId, long buyTokenQuantity,
int permissionId, String[] priKeys, WalletBlockingStub blockingStubFull) {

MarketContract.MarketSellAssetContract.Builder builder = MarketContract.MarketSellAssetContract
.newBuilder();
builder
.setOwnerAddress(ByteString.copyFrom(owner))
.setSellTokenId(ByteString.copyFrom(sellTokenId))
.setSellTokenQuantity(sellTokenQuantity)
.setBuyTokenId(ByteString.copyFrom(buyTokenId))
.setBuyTokenQuantity(buyTokenQuantity);

TransactionExtention transactionExtention = blockingStubFull.marketSellAsset(builder.build());
if (transactionExtention == null) {
return false;
}
Return ret = transactionExtention.getResult();
if (!ret.getResult()) {
System.out.println("Code = " + ret.getCode());
System.out.println("Message = " + ret.getMessage().toStringUtf8());
return false;
}
Transaction transaction = transactionExtention.getTransaction();
if (transaction == null || transaction.getRawData().getContractCount() == 0) {
System.out.println("Transaction is empty");
return false;
}

if (transaction.getRawData().getContract(0).getType()
!= ContractType.MarketSellAssetContract) {
return false;
}

try {
transaction = setPermissionId(transaction, permissionId);
transaction = signTransaction(transaction, blockingStubFull, priKeys);
} catch (CancelException e) {
e.printStackTrace();
}
return broadcastTransaction(transaction, blockingStubFull);

}

/**
* constructor.
*/
public static boolean marketCancelOrder(byte[] owner, byte[] orderId,
int permissionId, String[] priKeys,
WalletBlockingStub blockingStubFull) {

MarketContract.MarketCancelOrderContract.Builder builder = MarketContract
.MarketCancelOrderContract.newBuilder();
builder.setOwnerAddress(ByteString.copyFrom(owner)).setOrderId(ByteString.copyFrom(orderId));

TransactionExtention transactionExtention = blockingStubFull.marketCancelOrder(builder.build());

if (transactionExtention == null) {
return false;
}
Return ret = transactionExtention.getResult();
if (!ret.getResult()) {
System.out.println("Code = " + ret.getCode());
System.out.println("Message = " + ret.getMessage().toStringUtf8());
return false;
}
Transaction transaction = transactionExtention.getTransaction();
if (transaction == null || transaction.getRawData().getContractCount() == 0) {
System.out.println("Transaction is empty");
return false;
}

if (transaction.getRawData().getContract(0).getType()
!= ContractType.MarketCancelOrderContract) {
System.out.println("Wrong ContractType :"
+ transaction.getRawData().getContract(0).getType());
return false;
}

try {
transaction = setPermissionId(transaction, permissionId);
transaction = signTransaction(transaction,blockingStubFull,priKeys);
} catch (CancelException e) {
e.printStackTrace();
}
return broadcastTransaction(transaction, blockingStubFull);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import stest.tron.wallet.common.client.utils.PublicMethedForMutiSign;

@Slf4j
public class WalletTestMutiSign017 {
public class MutiSignAccountPermissionUpdateTest {

private static final long now = System.currentTimeMillis();
private static final long totalSupply = now;
Expand Down Expand Up @@ -75,15 +75,15 @@ public void beforeSuite() {
* constructor.
*/

@BeforeClass(enabled = false)
@BeforeClass(enabled = true)
public void beforeClass() {
channelFull = ManagedChannelBuilder.forTarget(fullnode)
.usePlaintext(true)
.build();
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
}

@Test(enabled = false)
@Test(enabled = true)
public void testMutiSign1UpdatePermission() {
ecKey1 = new ECKey(Utils.getRandom());
manager1Address = ecKey1.getAddress();
Expand Down Expand Up @@ -185,7 +185,7 @@ public void testMutiSign1UpdatePermission() {
/**
* constructor.
*/
@AfterClass(enabled = false)
@AfterClass(enabled = true)
public void shutdown() throws InterruptedException {
if (channelFull != null) {
channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import stest.tron.wallet.common.client.utils.PublicMethedForMutiSign;

@Slf4j
public class WalletTestMutiSign011 {
public class MutiSignAccountPermissionUpdateTest002 {

private static final long now = System.currentTimeMillis();
private static final long totalSupply = now;
Expand Down Expand Up @@ -75,15 +75,15 @@ public void beforeSuite() {
* constructor.
*/

@BeforeClass(enabled = false)
@BeforeClass(enabled = true)
public void beforeClass() {
channelFull = ManagedChannelBuilder.forTarget(fullnode)
.usePlaintext(true)
.build();
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
}

@Test(enabled = false)
@Test(enabled = true)
public void testMutiSign1UpdatePermission() {
ecKey1 = new ECKey(Utils.getRandom());
manager1Address = ecKey1.getAddress();
Expand Down Expand Up @@ -185,7 +185,7 @@ public void testMutiSign1UpdatePermission() {
/**
* constructor.
*/
@AfterClass(enabled = false)
@AfterClass(enabled = true)
public void shutdown() throws InterruptedException {
if (channelFull != null) {
channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import stest.tron.wallet.common.client.utils.PublicMethedForMutiSign;

@Slf4j
public class WalletTestMutiSign013 {
public class MutiSignAccountTest {

private final String testKey002 = Configuration.getByPath("testng.conf")
.getString("foundationAccount.key1");
Expand Down Expand Up @@ -83,15 +83,15 @@ public void beforeSuite() {
* constructor.
*/

@BeforeClass(enabled = false)
@BeforeClass(enabled = true)
public void beforeClass() {
channelFull = ManagedChannelBuilder.forTarget(fullnode)
.usePlaintext(true)
.build();
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
}

@Test(enabled = false)
@Test(enabled = true)
public void testMutiSignForAccount() {
ecKey1 = new ECKey(Utils.getRandom());
manager1Address = ecKey1.getAddress();
Expand Down Expand Up @@ -210,7 +210,7 @@ public void testMutiSignForAccount() {
/**
* constructor.
*/
@AfterClass(enabled = false)
@AfterClass(enabled = true)
public void shutdown() throws InterruptedException {
if (channelFull != null) {
channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import stest.tron.wallet.common.client.utils.PublicMethedForMutiSign;

@Slf4j
public class WalletTestMutiSign007 {
public class MutiSignAccountTest002 {

private final String testKey002 = Configuration.getByPath("testng.conf")
.getString("foundationAccount.key1");
Expand Down Expand Up @@ -83,15 +83,15 @@ public void beforeSuite() {
* constructor.
*/

@BeforeClass(enabled = false)
@BeforeClass(enabled = true)
public void beforeClass() {
channelFull = ManagedChannelBuilder.forTarget(fullnode)
.usePlaintext(true)
.build();
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
}

@Test(enabled = false)
@Test(enabled = true)
public void testMutiSignForAccount() {
ecKey1 = new ECKey(Utils.getRandom());
manager1Address = ecKey1.getAddress();
Expand Down Expand Up @@ -210,7 +210,7 @@ public void testMutiSignForAccount() {
/**
* constructor.
*/
@AfterClass(enabled = false)
@AfterClass(enabled = true)
public void shutdown() throws InterruptedException {
if (channelFull != null) {
channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import stest.tron.wallet.common.client.utils.PublicMethedForMutiSign;

@Slf4j
public class WalletTestMutiSign012 {
public class MutiSignAssetTest {

private static final long now = System.currentTimeMillis();
private static final long totalSupply = now;
Expand Down Expand Up @@ -76,15 +76,15 @@ public void beforeSuite() {
* constructor.
*/

@BeforeClass(enabled = false)
@BeforeClass(enabled = true)
public void beforeClass() {
channelFull = ManagedChannelBuilder.forTarget(fullnode)
.usePlaintext(true)
.build();
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
}

@Test(enabled = false)
@Test(enabled = true)
public void testMutiSign1CreateAssetissue() {
ecKey1 = new ECKey(Utils.getRandom());
manager1Address = ecKey1.getAddress();
Expand Down Expand Up @@ -184,7 +184,7 @@ public void testMutiSign1CreateAssetissue() {
* constructor.
*/

@Test(enabled = false)
@Test(enabled = true)
public void testMutiSign2TransferAssetissue() {
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.printAddress(manager1Key);
Expand Down Expand Up @@ -222,7 +222,7 @@ public void testMutiSign2TransferAssetissue() {
* constructor.
*/

@Test(enabled = false)
@Test(enabled = true)
public void testMutiSign3ParticipateAssetissue() {
ecKey4 = new ECKey(Utils.getRandom());
participateAddress = ecKey4.getAddress();
Expand Down Expand Up @@ -305,7 +305,7 @@ public void testMutiSign3ParticipateAssetissue() {
* constructor.
*/

@Test(enabled = false)
@Test(enabled = true)
public void testMutiSign4updateAssetissue() {
url = "MutiSign001_update_url" + Long.toString(now);
ownerKeyString[0] = ownerKey;
Expand Down Expand Up @@ -341,7 +341,7 @@ public void testMutiSign4updateAssetissue() {
/**
* constructor.
*/
@AfterClass(enabled = false)
@AfterClass(enabled = true)
public void shutdown() throws InterruptedException {
if (channelFull != null) {
channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import stest.tron.wallet.common.client.utils.PublicMethedForMutiSign;

@Slf4j
public class WalletTestMutiSign006 {
public class MutiSignAssetTest002 {

private static final long now = System.currentTimeMillis();
private static final long totalSupply = now;
Expand Down Expand Up @@ -76,15 +76,15 @@ public void beforeSuite() {
* constructor.
*/

@BeforeClass(enabled = false)
@BeforeClass(enabled = true)
public void beforeClass() {
channelFull = ManagedChannelBuilder.forTarget(fullnode)
.usePlaintext(true)
.build();
blockingStubFull = WalletGrpc.newBlockingStub(channelFull);
}

@Test(enabled = false)
@Test(enabled = true)
public void testMutiSign1CreateAssetissue() {
ecKey1 = new ECKey(Utils.getRandom());
manager1Address = ecKey1.getAddress();
Expand Down Expand Up @@ -184,7 +184,7 @@ public void testMutiSign1CreateAssetissue() {
* constructor.
*/

@Test(enabled = false)
@Test(enabled = true)
public void testMutiSign2TransferAssetissue() {
PublicMethed.waitProduceNextBlock(blockingStubFull);
PublicMethed.printAddress(manager1Key);
Expand Down Expand Up @@ -222,7 +222,7 @@ public void testMutiSign2TransferAssetissue() {
* constructor.
*/

@Test(enabled = false)
@Test(enabled = true)
public void testMutiSign3ParticipateAssetissue() {
ecKey4 = new ECKey(Utils.getRandom());
participateAddress = ecKey4.getAddress();
Expand Down Expand Up @@ -305,7 +305,7 @@ public void testMutiSign3ParticipateAssetissue() {
* constructor.
*/

@Test(enabled = false)
@Test(enabled = true)
public void testMutiSign4updateAssetissue() {
url = "MutiSign001_update_url" + Long.toString(now);
ownerKeyString[0] = ownerKey;
Expand Down Expand Up @@ -341,7 +341,7 @@ public void testMutiSign4updateAssetissue() {
/**
* constructor.
*/
@AfterClass(enabled = false)
@AfterClass(enabled = true)
public void shutdown() throws InterruptedException {
if (channelFull != null) {
channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS);
Expand Down
Loading

0 comments on commit 395582f

Please sign in to comment.