|
| 1 | +package stest.tron.wallet.onlineStress; |
| 2 | + |
| 3 | +import com.google.protobuf.ByteString; |
| 4 | +import io.grpc.ManagedChannel; |
| 5 | +import io.grpc.ManagedChannelBuilder; |
| 6 | +import java.util.HashMap; |
| 7 | +import java.util.concurrent.TimeUnit; |
| 8 | +import lombok.extern.slf4j.Slf4j; |
| 9 | +import org.testng.Assert; |
| 10 | +import org.testng.annotations.AfterClass; |
| 11 | +import org.testng.annotations.BeforeClass; |
| 12 | +import org.testng.annotations.BeforeSuite; |
| 13 | +import org.testng.annotations.Test; |
| 14 | +import org.tron.api.WalletGrpc; |
| 15 | +import org.tron.common.crypto.ECKey; |
| 16 | +import org.tron.common.utils.ByteArray; |
| 17 | +import org.tron.common.utils.Utils; |
| 18 | +import org.tron.core.Wallet; |
| 19 | +import stest.tron.wallet.common.client.Configuration; |
| 20 | +import stest.tron.wallet.common.client.Parameter.CommonConstant; |
| 21 | +import stest.tron.wallet.common.client.utils.Base58; |
| 22 | +import stest.tron.wallet.common.client.utils.PublicMethed; |
| 23 | +import stest.tron.wallet.common.client.utils.PublicMethedForMutiSign; |
| 24 | + |
| 25 | +@Slf4j |
| 26 | +public class TestMutiSignStress { |
| 27 | + |
| 28 | + private final String testKey002 = Configuration.getByPath("testng.conf") |
| 29 | + .getString("foundationAccount.key2"); |
| 30 | + private final byte[] fromAddress = PublicMethed.getFinalAddress(testKey002); |
| 31 | + private final String witnessKey001 = Configuration.getByPath("testng.conf") |
| 32 | + .getString("witness.key1"); |
| 33 | + private final byte[] witnessAddress = PublicMethed.getFinalAddress(witnessKey001); |
| 34 | + |
| 35 | + |
| 36 | + private ManagedChannel channelFull = null; |
| 37 | + private WalletGrpc.WalletBlockingStub blockingStubFull = null; |
| 38 | + private String fullnode = Configuration.getByPath("testng.conf").getStringList("fullnode.ip.list") |
| 39 | + .get(0); |
| 40 | + ByteString assetAccountId1; |
| 41 | + String[] ownerKeyString = new String[1]; |
| 42 | + String accountPermissionJson = ""; |
| 43 | + |
| 44 | + @BeforeSuite |
| 45 | + public void beforeSuite() { |
| 46 | + Wallet wallet = new Wallet(); |
| 47 | + Wallet.setAddressPreFixByte(CommonConstant.ADD_PRE_FIX_BYTE_MAINNET); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * constructor. |
| 52 | + */ |
| 53 | + |
| 54 | + @BeforeClass(enabled = true) |
| 55 | + public void beforeClass() { |
| 56 | + channelFull = ManagedChannelBuilder.forTarget(fullnode) |
| 57 | + .usePlaintext(true) |
| 58 | + .build(); |
| 59 | + blockingStubFull = WalletGrpc.newBlockingStub(channelFull); |
| 60 | + } |
| 61 | + |
| 62 | + @Test(enabled = true,threadPoolSize = 30, invocationCount = 30) |
| 63 | + public void testMutiSignForAccount() { |
| 64 | + PublicMethed.printAddress(testKey002); |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + ECKey ecKey4 = new ECKey(Utils.getRandom()); |
| 71 | + byte[] newAddress = ecKey4.getAddress(); |
| 72 | + String newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | + ECKey ecKey3 = new ECKey(Utils.getRandom()); |
| 79 | + byte[] ownerAddress = ecKey3.getAddress(); |
| 80 | + |
| 81 | + Assert.assertTrue(PublicMethed.sendcoin(ownerAddress,9968981537400L,fromAddress,testKey002, |
| 82 | + blockingStubFull)); |
| 83 | + PublicMethed.waitProduceNextBlock(blockingStubFull); |
| 84 | + PublicMethed.waitProduceNextBlock(blockingStubFull); |
| 85 | + PublicMethed.waitProduceNextBlock(blockingStubFull); |
| 86 | + ECKey ecKey1 = new ECKey(Utils.getRandom()); |
| 87 | + byte[] manager1Address = ecKey1.getAddress(); |
| 88 | + String manager1Key = ByteArray.toHexString(ecKey1.getPrivKeyBytes()); |
| 89 | + String[] permissionKeyString = new String[3]; |
| 90 | + permissionKeyString[0] = manager1Key; |
| 91 | + ECKey ecKey2 = new ECKey(Utils.getRandom()); |
| 92 | + byte[] manager2Address = ecKey2.getAddress(); |
| 93 | + String manager2Key = ByteArray.toHexString(ecKey2.getPrivKeyBytes()); |
| 94 | + permissionKeyString[1] = manager2Key; |
| 95 | + String ownerKey = ByteArray.toHexString(ecKey3.getPrivKeyBytes()); |
| 96 | + permissionKeyString[2] = ownerKey; |
| 97 | + String[] ownerKeyString = new String[1]; |
| 98 | + ownerKeyString[0] = ownerKey; |
| 99 | + |
| 100 | + accountPermissionJson = |
| 101 | + "{\"owner_permission\":{\"type\":0,\"permission_name\":\"owner\",\"threshold\":3,\"keys\":[" |
| 102 | + + "{\"address\":\"" + PublicMethed.getAddressString(ownerKey) + "\",\"weight\":1}," |
| 103 | + + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," |
| 104 | + + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}]}," |
| 105 | + + "\"active_permissions\":[{\"type\":2,\"permission_name\":\"active0\",\"threshold\":2," |
| 106 | + + "\"operations\":\"7fff1fc0033e0000000000000000000000000000000000000000000000000000\"," |
| 107 | + + "\"keys\":[" |
| 108 | + + "{\"address\":\"" + PublicMethed.getAddressString(manager1Key) + "\",\"weight\":1}," |
| 109 | + + "{\"address\":\"" + PublicMethed.getAddressString(manager2Key) + "\",\"weight\":1}" |
| 110 | + + "]}]}"; |
| 111 | + logger.info(accountPermissionJson); |
| 112 | + PublicMethedForMutiSign.accountPermissionUpdate(accountPermissionJson,ownerAddress,ownerKey, |
| 113 | + blockingStubFull,ownerKeyString); |
| 114 | + |
| 115 | + //permissionKeyString[0] = ownerKey; |
| 116 | + |
| 117 | + String[] ownerKeyString1 = new String[3]; |
| 118 | + ownerKeyString1[0] = ownerKey; |
| 119 | + ownerKeyString1[1] = manager1Key; |
| 120 | + ownerKeyString1[2] = manager2Key; |
| 121 | + PublicMethed.waitProduceNextBlock(blockingStubFull); |
| 122 | + PublicMethed.waitProduceNextBlock(blockingStubFull); |
| 123 | + PublicMethed.waitProduceNextBlock(blockingStubFull); |
| 124 | + |
| 125 | + |
| 126 | + Integer i = 0; |
| 127 | + while (i++ <= 1000) { |
| 128 | + ecKey4 = new ECKey(Utils.getRandom()); |
| 129 | + newAddress = ecKey4.getAddress(); |
| 130 | + newKey = ByteArray.toHexString(ecKey4.getPrivKeyBytes()); |
| 131 | + PublicMethed.printAddress(newKey); |
| 132 | + |
| 133 | + |
| 134 | + PublicMethedForMutiSign.sendcoin( |
| 135 | + newAddress,4000000L,ownerAddress,ownerKey,blockingStubFull,ownerKeyString1); |
| 136 | + PublicMethedForMutiSign.freezeBalance( |
| 137 | + ownerAddress,1000000L,0,ownerKey,blockingStubFull,ownerKeyString1); |
| 138 | + PublicMethedForMutiSign.freezeBalanceGetEnergy( |
| 139 | + ownerAddress,1000000L,0,1,ownerKey,blockingStubFull,ownerKeyString1); |
| 140 | + PublicMethedForMutiSign.freezeBalanceForReceiver( |
| 141 | + ownerAddress,1000000L,0,0,ByteString.copyFrom(newAddress), |
| 142 | + ownerKey,blockingStubFull,ownerKeyString1); |
| 143 | + PublicMethedForMutiSign.unFreezeBalance( |
| 144 | + ownerAddress,ownerKey,0,null,blockingStubFull,ownerKeyString1); |
| 145 | + PublicMethedForMutiSign.unFreezeBalance( |
| 146 | + ownerAddress,ownerKey,0,newAddress,blockingStubFull,ownerKeyString1); |
| 147 | + PublicMethedForMutiSign.updateAccount( |
| 148 | + ownerAddress,Long.toString(System.currentTimeMillis()).getBytes(),ownerKey, |
| 149 | + blockingStubFull,ownerKeyString1); |
| 150 | + } |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * constructor. |
| 158 | + */ |
| 159 | + @AfterClass(enabled = true) |
| 160 | + public void shutdown() throws InterruptedException { |
| 161 | + if (channelFull != null) { |
| 162 | + channelFull.shutdown().awaitTermination(5, TimeUnit.SECONDS); |
| 163 | + } |
| 164 | + } |
| 165 | +} |
| 166 | + |
| 167 | + |
0 commit comments